Plot on different tile during a loop

180 ビュー (過去 30 日間)
Pin-Hao Cheng
Pin-Hao Cheng 2020 年 11 月 17 日
回答済み: Hrishikesh Borate 2020 年 11 月 20 日
Hi all-
Similar to the question asked here, but mine was about plotting on different tiles during a loop.
If we are talking about plotting on different figure, I would just call the figure() command an input argument:
>> figure(1)
>> plot(1:10)
>> figure(2)
>> plot(2:11)
Any clue how could I do that in tiledlayout?
For example, I will have:
tiledlayout(2,2)
nexttile; % tile 1
plot(x,y1)
nexttile; % tile 2
plot(x,y2)
nexttile([1 2]); % tile 3
plot(x,y3)
Now I wish to go back to tile 1 and plot new stuff on it, is there anyway to do that? I have searched around but doesnt seem to have a solution out there.
Any help would be greatly appreaciated!

採用された回答

Monisha Nalluru
Monisha Nalluru 2020 年 11 月 20 日
編集済み: Monisha Nalluru 2020 年 11 月 20 日
nexttile is used to create axes in tilelayout.
So if we store the axes handles for each tile then we can plot new changes to existing tile by shifting to that axes handle using axes function.
As an example
tiledlayout(2,2);
[X,Y,Z] = peaks(20);
% Tile 1
a=nexttile;
surf(X,Y,Z);
% Tile 2
b=nexttile;
contour(X,Y,Z);
% Tile 3
c=nexttile;
imagesc(Z);
% Tile 4
d=nexttile;
plot3(X,Y,Z);
% change the plot of Tile 1
axes(a) % chaging the current axes handle to Tile 1 axes handle
plot([1:10]) % overwritng the existing plot
Hope this helps!

その他の回答 (1 件)

Hrishikesh Borate
Hrishikesh Borate 2020 年 11 月 20 日
Hi,
I understand that you want to access a previous tile in a tiled layout and plot a graph at that tile. The syntax to access a particular tile is :-
nexttile(tile_location);
Following is the code when you want to go to first tile and plot a graph on top of existing plot.
nexttile(1)
hold on
plot(x, y);
hold off
Following is the code when you want to go to first tile and replace the previous plot / plot a new plot.
nexttile(1)
plot(x, y);
For more information, refer to nexttile.

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

製品


リリース

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by