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

3 views (last 30 days)
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!

Accepted Answer

DGM
DGM on 1 Dec 2021
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;

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!