Plot in a figure of a gui and simultaneously open a new figure

3 vues (au cours des 30 derniers jours)
Francesca Mosca
Francesca Mosca le 27 Mai 2016
Commenté : Francesca Mosca le 30 Mai 2016
Hi!I have a gui with two figure, the main one and another one that I use to set parameters. In the main one I have two axes, in one I have a "static" plot, in the other one I plot continuously with a while().My problem is that when I open the second figure while I am plotting in the main one, I see the "dinamic" plot in the open one and not in the main gui. How can I set the axes and the figure so that I always see my plot in the correct axes?Thank you so much!

Réponses (1)

TastyPastry
TastyPastry le 27 Mai 2016
You can switch the focus between an axes and figure by calling them with an output, the figure handle, and using the axes() and figure() functions.
For example:
fig1 = figure();
ax = axes();
fig2 = figure();
Creates two figures with an axes on the first figure.
Here, because fig2 was called last, the focus is on fig2. If I were to call gcf (get current figure), I'd get fig2's properties.
If I want to plot on fig1's axes:
axes(ax);
Will automatically switch focus to fig1, the parent of ax.
  1 commentaire
Francesca Mosca
Francesca Mosca le 30 Mai 2016
I post the function callback of the button that starts the plot:
function startvis_Callback(hObject, eventdata, handles)
% hObject handle to startvis (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
hgui=getappdata(0,'hgui');
setappdata(hgui,'startv',1);
axes(handles.figvis)
array=[];
i=0;
T=0:0.002:12;
guidata(hObject, handles)
while getappdata(hgui,'startv')==1
i=i+1;
a=fread(handles.s,60,'uint16');
fprintf(getappdata(hgui,'f'),'%d',a);
if i>100
i=1;
T=T(end)+0.002:0.002:T(end)+12;
array=a.*3/1023;
else
array=[array;a.*3/1023];
end
axes(handles.figvis)
plot(T(1:60*i),array),grid on,xlabel('Time [s]'),ylabel('Voltage [V]')
axis([T(1),T(end),0,3.5])
pause(0.0000000000000000000000000000000000000000001);
end
While I am in the figure that contains the axes everything work fine! but when I access to another figure with a button (that is in this figure where I plot), the plot is visualised in this new figure and I don't want this to happens!

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by