Problem in plotting the string variable

2 visualizzazioni (ultimi 30 giorni)
Prakhar Modi
Prakhar Modi il 26 Ago 2019
Commentato: Ted Shultz il 26 Ago 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 Commento
Stephen23
Stephen23 il 26 Ago 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

Accedi per commentare.

Risposte (4)

KALYAN ACHARJYA
KALYAN ACHARJYA il 26 Ago 2019
Modificato: KALYAN ACHARJYA il 26 Ago 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 il 26 Ago 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 il 26 Ago 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 il 26 Ago 2019
Modificato: dpb il 26 Ago 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 Commento
Ted Shultz
Ted Shultz il 26 Ago 2019
Cool solution! Here is the documentation for anyone else who had never heard of this before (like me): categorical doc page

Accedi per commentare.

Categorie

Scopri di più su Labels and Annotations in Help Center e File Exchange

Prodotti


Release

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by