I want to save view(net) as an image in 2013b. I searched (https://stackoverflow.com/questions/14919140/matlab-how-to-save-view-configuration) and used them but not succeeded.
5 views (last 30 days)
Show older comments
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 19-Nov-2023 14:43:06
%
% This script assumes these variables are defined:
%
% t - input data.
% z_num - target data.
x = t';
t = z_num';
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainbr'; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 12;
net = fitnet(hiddenLayerSize,trainFcn);
net.trainParam.epochs = 20;
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y_P98 = net(x);
e_P98 = gsubtract(t,y_P98);
performance = perform(net,t,y_P98);
view(net);
0 Comments
Answers (1)
Riya
on 13 Aug 2025
Hi Farooq,
I understand that you are trying to save the visualization generated by MATLAB’s “view(net)” function in R2013b as an image.
In the code that you provided, the “view(net)” opens the Neural Network Toolbox Viewer, which is not a standard MATLAB figure. This is why direct commands such as “saveas” or “print” may not work if applied without first obtaining the figure handle.
To resolve this, you should store the function handle returned by “view(net)” and then use “print” or “saveas” function to export it as an image. Kindly refer to the corrected code below for the same:
% View the network and get the handle
h = view(net);
% Ensure the figure is rendered
drawnow;
% Save as PNG
print(h, '-dpng', 'network_view.png');
% (Optional) Save as JPEG
% print(h, '-djpeg', 'network_view.jpg');
% (Optional) Save high resolution (300 DPI)
% print(h, '-dpng', '-r300', 'network_view_highres.png');
Here, the command “h = view(net)” will return a function handle to the Neural Network diagram window, which can then be passed to “print” or “saveas” function for saving in various formats.
With this adjustment, now you will be able to save the network visualization directly from MATLAB R2013b into an image file easily.
For further reference on exporting figures, kindly refer to the following official documentation:
1 Comment
DGM
on 13 Aug 2025
In current versions, view() does not have any documented support for returning any output arguments.
[x,t] = iris_dataset;
net = patternnet;
net = configure(net,x,t);
h = view(net)
It's not clear what the behavior would have been in R2013b. There are other posts which suggest that it can return a Java figure, which I suspect would have been an undocumented behavior at the time, and something which would have likely been removed since. If what it returned was not an HG figure, print() and saveas() wouldn't work on it.
The top answer here is in the appropriate time frame.
Disclaimer: I do not have this toolbox, and am completely unfamiliar with the revision history of its components. I just found it doubtful that a GUI tool would be captured by print(). There is plenty of room for me to be wrong, but it's fair to question a curiously simplistic and self-contradictory AI generated answer to very specific legacy versions of software.
See Also
Categories
Find more on Image Data Workflows in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!