using struct to plot multiple set of data on multiple figures [figure properties]
2 ビュー (過去 30 日間)
古いコメントを表示
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)?
0 件のコメント
採用された回答
Matt J
2021 年 4 月 28 日
編集済み: Matt J
2021 年 4 月 28 日
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 件のコメント
Matt J
2021 年 4 月 28 日
A figure can contain many axes. title() needs to be told which axis in the figure to place the title in.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!