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 CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by