Problem in plotting the string variable

2 views (last 30 days)
Prakhar Modi
Prakhar Modi on 26 Aug 2019
Commented: Ted Shultz on 26 Aug 2019
Hello everyone,
Rough_y=[4;5;8;3;12;14;9;11;17;17;11;14;19;25;15]
Station=['a';'b';'c';'d';'e';'f';'g';'h';'i';'j';'k';'l';'m';'n';'o']
Now I am using
plot(Rough_y)
set(gcs,'Xticklabel',Station)
So what i found out that as Rough_y is 15x1 so the plot shows, only 5 points till e on the x axis. If Rough_y is 11x1 than it is showing whole 11 on the X axis. So is their a limit for this because if I am using bar instead of plot that it is giving correct graph but i want it as line graph with whole 15 values.
Thanks in advance
  1 Comment
Stephen23
Stephen23 on 26 Aug 2019
Simpler than writing out half of the alphabet:
>> Station= ('a':'o').'
Station =
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o

Sign in to comment.

Answers (4)

KALYAN ACHARJYA
KALYAN ACHARJYA on 26 Aug 2019
Edited: KALYAN ACHARJYA on 26 Aug 2019
Rough_y=[4;5;8;3;12;14;9;11;17;17;11;14;19;25;15]
Station=['a';'b';'c';'d';'e';'f';'g';'h';'i';'j';'k';'l';'m';'n';'o']
plot(Rough_y)
set(gca,'xtick',[1:length(Rough_y)],'xticklabel',Station)
346.png

Alex Mcaulley
Alex Mcaulley on 26 Aug 2019
Do you mean this?
Rough_y=[4;5;8;3;12;14;9;11;17;17;11;14;19;25;15]
Station=['a';'b';'c';'d';'e';'f';'g';'h';'i';'j';'k';'l';'m';'n';'o']
plot(Rough_y)
ax = gca;
%For R2014b or later
ax.XTick = 1:numel(Station);
ax.XTickLabel = Station;
%For previous versions
set(gca,'XTick',1:numel(Station))
set(gca,'XTickLabel',Station)

Ted Shultz
Ted Shultz on 26 Aug 2019
Matlab only labels tick marks that exist (about every 5 "units" in this case). Make to make the ticks every mark, use the xTick property. I think this code does what you are trying to do:
Rough_y=[4;5;8;3;12;14;9;11;17;17;11;14;19;25;15]
Station={'a';'b';'c';'d';'e';'f';'g';'h';'i';'j';'k';'l';'m';'n';'o'}
figure
plot(Rough_y)
set(gca,'Xticklabel',Station)
set(gca,'Xtick',1:numel(Rough_y))

dpb
dpb on 26 Aug 2019
Edited: dpb on 26 Aug 2019
Nobody seems to have stumbled onto the easy answer as of yet...leaving the variable as a string when it is clearly a categorical variable type is the basic problem--
Station=categorical(cellstr(['a':'o'].'));
plot(Station,Rough_y)
  1 Comment
Ted Shultz
Ted Shultz on 26 Aug 2019
Cool solution! Here is the documentation for anyone else who had never heard of this before (like me): categorical doc page

Sign in to comment.

Categories

Find more on Labels and Annotations in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!