Problem in plotting the string variable

2 ビュー (過去 30 日間)
Prakhar Modi
Prakhar Modi 2019 年 8 月 26 日
コメント済み: Ted Shultz 2019 年 8 月 26 日
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 件のコメント
Stephen23
Stephen23 2019 年 8 月 26 日
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

サインインしてコメントする。

回答 (4 件)

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 8 月 26 日
編集済み: KALYAN ACHARJYA 2019 年 8 月 26 日
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 2019 年 8 月 26 日
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 2019 年 8 月 26 日
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 2019 年 8 月 26 日
編集済み: dpb 2019 年 8 月 26 日
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 件のコメント
Ted Shultz
Ted Shultz 2019 年 8 月 26 日
Cool solution! Here is the documentation for anyone else who had never heard of this before (like me): categorical doc page

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLabels and Annotations についてさらに検索

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by