How can I plot xticklabels from a 3-column matrix?

2 ビュー (過去 30 日間)
Rafael Cordero
Rafael Cordero 2021 年 12 月 1 日
コメント済み: Rafael Cordero 2021 年 12 月 2 日
Hello again,
So I asked a quesiton previously and it got answered but I realized that really it was the wrong question because I couldn't do what I wanted to how in the way I intented. My bad!
Imagine I have a 3-column numeric matrix A:
A =
[10 20 30;
30 40 50;
50 60 70;
80 90 100;
110 120 130;
140 150 160];
I have a plot, lets say it is a line plot of a vector V of 6 elments:
V = [3 4 2 5 4 5];
I want the x-ticks of this plot to be the rows of A.
E.g. the x-tick of value of V(1) = 3, should be '10 20 30', and the x-tick value of V(2) = 4 should be '30 40 50'.
If possible, it would be amazing if each of these threes values are displayed on three seperate lines:
So
'10
20
30'
Instead of '10 20 30' (for the x-tick value of V(1) = 3). This would improve readability for cases where V is very long.
Thank you!

採用された回答

DGM
DGM 2021 年 12 月 1 日
You can try something like Adam's answer here:
V = [3 4 2 5 4 5];
A =[10 20 30;
30 40 50;
50 60 70;
80 90 100;
110 120 130;
140 150 160];
plot(V)
labels = compose('%d',A.');
labels = sprintf('%s\\newline%s\\newline%s\n', labels{:});
hax = gca;
hax.XTick = 1:numel(V);
hax.XTickLabels = labels;

その他の回答 (0 件)

カテゴリ

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

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by