Problem in plotting the string variable

1 vue (au cours des 30 derniers jours)
Prakhar Modi
Prakhar Modi le 26 Août 2019
Commenté : Ted Shultz le 26 Août 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 commentaire
Stephen23
Stephen23 le 26 Août 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

Connectez-vous pour commenter.

Réponses (4)

KALYAN ACHARJYA
KALYAN ACHARJYA le 26 Août 2019
Modifié(e) : KALYAN ACHARJYA le 26 Août 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 le 26 Août 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 le 26 Août 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 le 26 Août 2019
Modifié(e) : dpb le 26 Août 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 commentaire
Ted Shultz
Ted Shultz le 26 Août 2019
Cool solution! Here is the documentation for anyone else who had never heard of this before (like me): categorical doc page

Connectez-vous pour commenter.

Catégories

En savoir plus sur Labels and Annotations dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by