フィルターのクリア

How to make subplot accept the positions like matrix?

13 ビュー (過去 30 日間)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2020 年 2 月 28 日
編集済み: gwoo 2021 年 7 月 29 日
Assume there is 3*3 subplot, subplot(3,3,p) which p gives the location like 1,2,... from left to right and so on. How can I set the p to accept value of the position like the matrix indexing. For example for the 1st subplot, instead of 1, p=(1,1) which shows the xth and yth of the subplot position.
Any idea?

採用された回答

Adam
Adam 2020 年 2 月 28 日
doc ind2sub
This will convert linear indices to n-dimensional subscripts.
e.g.
[p(1), p(2)] = ind2sub( [3, 3], 2 );
  2 件のコメント
Steven Lord
Steven Lord 2020 年 2 月 28 日
Note that subplot locations are row major, not column major like arrays in MATLAB. No, I don't know why. That decision predates the start of my tenure at MathWorks.
x = 0:0.1:2*pi;
A = zeros(3);
subplot(3, 3, 1) % upper-left corner
plot(x, sin(x))
title('Sine in position 1')
A(1) = 1; % upper-left corner
subplot(3, 3, 3) % upper-right corner
plot(x, cos(x))
title('Cosine in position 3')
A(3) = 3; % lower-left corner
subplot(3, 3, 8) % middle of the bottom row
plot(x, tan(x))
title('Tangent in position 8')
A(8) = 8 % middle of the last column
If you're using release R2019b or later, consider using the tiledlayout and nexttile functions instead of subplot.
gwoo
gwoo 2021 年 7 月 28 日
編集済み: gwoo 2021 年 7 月 29 日
tiledlayout is still, infuriatingly, row-major.
Update: I looked deeper and there is a tiledlayout property that lets you chooose row or column major. "TileIndexing" so.. yea. i guess it is the solution.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by