neural-networkmatlabmatlab-figure

Matlab - How to save view configuration of matlab neural network


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?


Solution

  • 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)