plotting at gui axes

조회 수: 1 (최근 30일)
Osama Alkurdi
Osama Alkurdi 2020년 3월 4일
답변: Geoff Hayes 2020년 3월 5일
let me explain my problem clearly
I have a script file which contains a certain function which plotting a data at different times and save the output figures as pictures (.jpg) in a certain directory
but when a call this script from the gui (callbacks).m file something weird happen
while my script running when I click at the gui window the plot start to appear at gui axes and not at the figure which cause to save the same figure many times
because the new plot start to show at gui axes and not at figure
is there is any solution for this complex problem
here is my code for more understanding
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
f=figure;
i=0;
t=zeros(1,75);
o=t;
a=t;
v=t;
for t_instantaneous=0:0.04:4.96
i=i+1;
[theta_instantaneous,omega_instantaneous,alpha_c,t_v_m_instantaneous]=raafawcaa06([0,0],4,-pi/3,-3,1,t_instantaneous);
t(1,i)=theta_instantaneous;
o(1,i)=omega_instantaneous;
a(1,i)=alpha_c;
v(1,i)=t_v_m_instantaneous;
axis([-10,10,-10,10])
pbaspect([1,1,1])
saveas(f,sprintf('pic%06d',i),'jpg')
hold off
end
close(f)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  댓글 수: 2
Geoff Hayes
Geoff Hayes 2020년 3월 5일
Osama - is the above code from your script? And you call this script from a (GUI) function callback? I'm not all that clear on your statement while my script running when I click at the gui window the plot start to appear at gui axes and not at the figure which cause to save the same figure many times. Do you mean that the GUI is running and you click a button in the GUI which then calls your script? And that the plot appears on the GUI rather than in the new figure? Please clarify.
Osama Alkurdi
Osama Alkurdi 2020년 3월 5일
yes, it is from my script.
yes, I am calling it from (GUI) function callback.
No, when I click a pushbutton the script start running and when I click at gui window while the script are still running the plot start to appear at gui axes and not at the figure that I created in the script.
I hope this explaination help to clarify the problem.

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

채택된 답변

Geoff Hayes
Geoff Hayes 2020년 3월 5일
Osama - I guess that the majority of your code to plot the results is in the raafawcaa06 function and I suspect that, like your above call to axis, you aren't specifying which axes to plot to (or update) and so those calls will always try to use the current axes. So when you press your GUI button and the script starts to run, everything is fine because the f figure is the current figure and so the axes on that will be drawn to and updated. When you then click back on your GUI, it becomes the current figure and so its axes become the current axes...and that is where the script will draw to (or update). What you could do is create the figure then create the axes and pass the handle of that axes to the raafawcaa06 and axis (and whatever else needs this handle) so that you only update that axes. For example, your code might look like
f=figure;
hAxes = gca; % <--- get the handle to the current axes on this figure that you just created
i=0;
t=zeros(1,75);
o=t;
a=t;
v=t;
for t_instantaneous=0:0.04:4.96
i=i+1;
%!!!!! pass hAxes into this function
[theta_instantaneous,omega_instantaneous,alpha_c,t_v_m_instantaneous]=raafawcaa06([0,0],4,-pi/3,-3,1,t_instantaneous, hAxes);
t(1,i)=theta_instantaneous;
o(1,i)=omega_instantaneous;
a(1,i)=alpha_c;
v(1,i)=t_v_m_instantaneous;
axis(hAxes, [-10,10,-10,10]); % <---- set the axes here
pbaspect([1,1,1])
saveas(f,sprintf('pic%06d',i),'jpg')
hold off
end
close(f)

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by