Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am trying to configure a neural network using matlab and newff command.

After that, I am trying to visualize my created configuration using the view command.

x = view(net);

How can I save the displayed window to a .png file? I have tried with saveas(x, 'figure.png', 'png') but it won't work? Do you know how can I do that from code?

share|improve this question
add comment (requires an account with 50 reputation)

2 Answers

up vote 2 down vote accepted

The created window is a pure Java figure (not MATLAB Handle Graphics). Try this to capture it:

%# neural net, and view it
net = feedforwardnet(5);
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();

%# print to file
set(hFig, 'PaperPositionMode', 'auto')
saveas(hFig, 'out.png')

%# close figure
close(hFig)
share|improve this answer
add comment (requires an account with 50 reputation)

I also have the same problem, specially when i try to save the Neural network toolbox (nntraintool) generated plots. I use snipping tools to capture those plots. However, please try to use the following one:

Identify the gfx object you need to snap-shoot (its handle). It will come from identifiable properties. Then you can use print option to save it to a file; you need to write the file name, the type; go to this link for more info (http://www.mathworks.com/help/matlab/ref/print.html).

For example, if you want to save the figure with the tag 'performance.fig', you may try:

h = findobj('Type', 'figure', 'tag', 'performance.fig');

    for k = 1:numel(h)

    print(h(k), sprintf('Pic%d.ps',k));

    end;

let me know if this helps, You have to modify codes up to your need. I also got this help from another person in this stackoverflow forum.

share|improve this answer
this will not work (neither findobj or allchild(0) will find the window in question) – Amro Apr 23 at 9:01
add comment (requires an account with 50 reputation)

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.