Borrar filtros
Borrar filtros

using struct to plot multiple set of data on multiple figures [figure properties]

2 visualizaciones (últimos 30 días)
So, I'm trying to plot multiple data set on multiple figures and it worked so far after I went through many answers posted on this forum. (thanks, everyone)
Although, When I was trying to add the title for the figure, the following code didn't work:
%% Plot
myFig = struct;
myFig(1).fig = figure(1);
clf(myFig(1).fig);
myFig(2).fig = figure(2);
clf(myFig(2).fig);
myFig(1).ax = axes('Parent', myFig(1).fig, 'NextPlot', 'add');
myFig(2).ax = axes('Parent', myFig(2).fig, 'NextPlot', 'add');
for j = 1:size(selectedData,3)
scatter(selectedData(:,1,j),selectedData(:,4,j),1,'Parent',myFig(1).ax)
scatter(selectedData(:,1,j),selectedData(:,6,j),1,'Parent',myFig(2).ax)
if j == 1
hold on
end
end
myFig(1).fig;
title('ABC vs. X')
myFig(2).fig;
title('DEF vs. X')
The result was that in there was no title in Figure 1 and the title for Figure 2 was 'DEF vs. X'.
If I comment out the last 2 lines, 'ABC vs. X' appears on Figure 2, which I thought it supposed to be on Figure 1.
However, when I changed the last 4 line to:
figure(1);
title('ABC vs. X')
figure(2);
title('DEF vs. X')
Everything works as what I want.
My question is why doesn't myFig(1).fig or myFig(1) works when I assigned figure(1) to them in the beginning?
Is there a way to include title using myFig(1).fig instead of figure(1)?

Respuesta aceptada

Matt J
Matt J el 28 de Abr. de 2021
Editada: Matt J el 28 de Abr. de 2021
My question is why doesn't myFig(1).fig or myFig(1) works ?
Neither of these are commands.
Is there a way to include title using myFig(1).fig instead of figure(1)?
The most direct solution:
title(myFig(1).ax,'ABC vs. X')
title(myFig(2).ax,'DEF vs. X')
  5 comentarios
Matt J
Matt J el 28 de Abr. de 2021
A figure can contain many axes. title() needs to be told which axis in the figure to place the title in.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by