Live Editor and view neural network

조회 수: 5 (최근 30일)
Grzegorz Knor
Grzegorz Knor 2017년 7월 27일
댓글: Baptiste Ottino 2017년 8월 8일
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)

채택된 답변

Baptiste Ottino
Baptiste Ottino 2017년 8월 8일
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.
  댓글 수: 2
Grzegorz Knor
Grzegorz Knor 2017년 8월 8일
Thank you for your answer. I've modified it a little bit, and now figure window can be closed automatically:
function outH = 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, 'Parent', hFig, 'units','normalized', 'position',[0 0 1 1])
%# close java window
jframe.setVisible(false);
jframe.dispose();
% capture figure as a frame
F = getframe(hFig);
% close current figure
close(hFig)
% display the captured image data using imshow
hFig = figure('Menubar','none', 'Position',[100 100 565 166]);
axes('units','normalized', 'position',[0 0 1 1])
imshow(F.cdata)
axis off
% return handle if needed
if nargout == 1
outH = hFig;
end
Baptiste Ottino
Baptiste Ottino 2017년 8월 8일
Pretty cool, thank you very much!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Sequence and Numeric Feature Data Workflows에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by