How do I add data to multiple figure windows in one loop?

4 visualizaciones (últimos 30 días)
Janna Hinchliff
Janna Hinchliff el 3 de Abr. de 2019
Respondida: Rik el 3 de Abr. de 2019
I want to make a loop where I plot two different parameters on two different figure windows, such that each iteration of the loop adds one plot to one window and another plot to a second window. For the one plot case I am using
fig4 = figure;
for ii = 1:length(plotmatrixcell)
plot(plotmatrixcell{ii}{2}(:,1),plotmatrixcell{ii}{2}(:,2),'r*')
hold on
end
which plots the data from each loop in the same figure window. I want to have something like this:
fig4 = figure;
fig5 = figure;
for ii = 1:length(plotmatrixcell)
% fig4
plot(plotmatrixcell{ii}{2}(:,1),plotmatrixcell{ii}{2}(:,2),'r*')
xlabel('Distance from VCSEL (mm)')
ylabel('Beam radius (mm)')
hold on
% fig5
currentfit = polyfit(plotmatrixcell{ii}{2}(:,1),plotmatrixcell{ii}{2}(:,2),1);
fitplot = polyval(currentfit, 0:10);
plot(0:10,fitplot,'k.--')
hold on
end
so that the first plot in each iteration is in one figure window and the second plot in each iteration is in a second figure window. How can I do this?

Respuesta aceptada

Rik
Rik el 3 de Abr. de 2019
Use explicit handles:
fig4=figure(4);
fig5=figure(5);
%'NextPlot','add' is equivalent to hold('on')
ax4=axes('Parent',fig4,'NextPlot','add');
ax5=axes('Parent',fig5,'NextPlot','add');
for ii = 1:length(plotmatrixcell)
% fig4
plot(plotmatrixcell{ii}{2}(:,1),plotmatrixcell{ii}{2}(:,2),'r*',...
'Parent',ax4)
% fig5
currentfit = polyfit(plotmatrixcell{ii}{2}(:,1),plotmatrixcell{ii}{2}(:,2),1);
fitplot = polyval(currentfit, 0:10);
plot(0:10,fitplot,'k.--',...
'Parent',ax5)
end
xlabel(ax4,'Distance from VCSEL (mm)')
ylabel(ax4,'Beam radius (mm)')

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by