필터 지우기
필터 지우기

Get Figure for Axes in GUI from function

조회 수: 8 (최근 30일)
Berk Demir
Berk Demir 2020년 4월 22일
편집: Adam Danz 2020년 4월 23일
Hello,
I have created a simple GUI which gets inputs from user and bring them to a outside function (lets say BRA). This BRA function calculates some numerical outputs and give them as output 'results'.
In this BRA code, I have also created a figure which starts with following and worked on over 50 lines. (So I cannot do that in GUİ, I have to create the figure in the function.)
figure('Renderer', 'painters', 'Position', [50 100 1200 900])
subplot(2,1,1)
%etc. etc.
So my question is: I have created an axes with a tag name axes1, however, I couldn't find a way to print this figure to this axes. My function gives the figure as POPUP window. I have tried to change the code above to aa=figure(....) and try to get the aa figure, but I couldn't manage it.
Can you please help me to get the figure from my outside function and print it on GUI axes?

답변 (1개)

Adam Danz
Adam Danz 2020년 4월 22일
편집: Adam Danz 2020년 4월 22일
(So I cannot do that in GUİ, I have to create the figure in the function.)
Why? Because it's 50 lines? That doesn't prevent you from creating the figure within the GUI.
I couldn't find a way to print this figure to this axes.
In the 2 lines of code provided, I see you're creating a new figure and creating a subplot. What exactly do you want to print on the GUI axes? One of the subplots?
To plot directly to an axes, use the axes handle,
% Example
plot(handles.axes1, x, y, '-b')
  댓글 수: 10
Berk Demir
Berk Demir 2020년 4월 22일
I didn't know that. Of course in BRA, I use the first figure command and then I use subplot and plot commands. But you say that I cannot put figure into the axes.
Thanks then.
Adam Danz
Adam Danz 2020년 4월 22일
편집: Adam Danz 2020년 4월 23일
Berk Demir, here's what's wrong and here's a solution.
What's wrong
A figure can contain axes. The figure is the parent and the axes is the child.
Axes can contain objects such as lines and scatter points. The axes is the parent and the line objects are children.
To illustrate further, a library can contain books but you can't put a library in a book. Similarly, you cannot put a figure in an axes.
You can copy the children from one axes to another axes.
Solution
If you can't directly plot the objects to your GUI axes using the method in my answer (which is the best solution) you can create the external figure and copy the content of it's axes to your GUI's axes.
% figHandle is the handle to the external figure
axesHandle = findobj(figHandle,'type','axes');
% Copy all children of the external axis to your GUI axes.
% If there are more then 1 axes found on the figure, this
% will only copy the first axes listed.
% Replace the 2nd input with your GUI axes handle.
copyobj(axesHandle(1).Children, axisHandle);

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

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by