Reputation: 7004
I have a list of labels:
lnames = {'nameA','nameB','nameC'}
and a vector with indices:
Y = [1; 1; 2; 3; 2];
index(1)
refers to nameA
, index(2)
to nameB
etc.
I want to show when a certain name is selected:
plot(Y, 'd')
This gives me a plot (on bigger scale as follows):
However, I want to replace the numerical values on the yaxis with the labels. Thus 1
becomes nameA
, 2
becomes nameB
, etc. It would look as follows:
How can this be achieved?
Upvotes: 1
Views: 82
Reputation: 5162
Y = [1; 1; 2; 3; 2];
yticks([1 2 3])
yticklabels({'nameA', 'nameB', 'nameC'})
plot(Y, 'd');
Upvotes: 0
Reputation: 22314
You can specify the YTick
and YTickLabel
for the axis of your plot as follows.
h = plot(Y, 'd');
h.Parent.YTick = 1:numel(lnames);
h.Parent.YTickLabel = lnames;
Upvotes: 2