plotting at gui axes
5 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Osama Alkurdi
il 4 Mar 2020
Risposto: Geoff Hayes
il 5 Mar 2020
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 Commenti
Geoff Hayes
il 5 Mar 2020
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.
Risposta accettata
Geoff Hayes
il 5 Mar 2020
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 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!