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 CenterFile Exchange에서 Labels and Annotations에 대해 자세히 알아보기

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by