Live Editor and view neural network

Grzegorz_knor · Jul 14, 2021 · 1.9K views
Question
Hi, I would like to add a neural network graphical diagram to my live script. Unfortunately command view produces new window instead of adding diagram to the live script.   To be clear, this code (in a Live Editor) attaches output of plot command directly to the live script, but does not include neural network diagram:     plot(1:10) net = patternnet; view(net)
Expert Answer
Profile picture of John Michell
John Michell PhD Expert
Answered Aug 31, 2026
You are experiencing this problem because the view(net) function does not output a figure, it outputs a Java object. I don't know a perfect work around, but you can try this:
 
 
 function newView(net)

 jframe = view(net);

 %# create it in a MATLAB figure
 hFig = figure('Menubar','none', 'Position',[100 100 565 166]);
 jpanel = get(jframe,'ContentPane');
 [~,h] = javacomponent(jpanel);
 set(h, 'units','normalized', 'position',[0 0 1 1])

 %# close java window
 jframe.setVisible(false);
 jframe.dispose();

I found this solution here. With this, you can have your network as a figure, and it will appear in the livescript. The only remaining issue is that the undocked figure window doesn't close once it has been plotted in the livescript, which is peculiar.

100% Run Guarantee 3-Hour Fast-Track Delivery

Need a Custom Version or Complete Simulation for This Problem?

Our 500+ PhD engineers build, debug, and optimize working MATLAB scripts and Simulink (.slx) models tailored to your exact assignment rubrics with zero plagiarism.

Tested on MATLAB R2024b / R2026a
Turnitin 0% Plagiarism Report
Free 7-Day Revisions Guarantee
Have a different question? Ask here

Get a Free Consultation or a Sample Assignment Review!