using struct to plot multiple set of data on multiple figures [figure properties]
Show older comments
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)?
Accepted Answer
More Answers (0)
Categories
Find more on Creating, Deleting, and Querying Graphics Objects in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!