Creating equally spaced x axis on plot function
조회 수: 8 (최근 30일)
이전 댓글 표시
Hi,
I am writing a function that adds 4 data sets onto one graph, each point from each data set corresponds to the same x value and I am trying to set these on the x-axis.
My function and what i have tried is shown below:
function [] = comp(team)
if team == 5
disp('You have chosen to compare all teams')
y1 = readtable('Arsenal.xlsx');
y1 = y1{:,4};
y2 = readtable('Liverpool.xlsx');
y2 = y2{:,4};
y3 = readtable('ManchesterUnited.xlsx');
y3 = y3{:,4};
y4 = readtable('Chelsea.xlsx');
y4 = y4{:,4};
x = (06:1:17)';
plot(x,y1,'gd',x,y2,'ro',x,y3,'k*',x,y4,'bx')
seasons={'06/07'; '07/08'; '08/09';'09/10';'10/11';'11/12';'12/13';'13/14';'14/15';'15/16';'16/17';'17/18'};
set(gca,'xticklabel',x)
xlabel('Season')
ylabel('Goals Scored')
legend('Arsenal','Liverpool','ManchesterUnited','Chelsea')
end
end
The X tick label does not use these values I have given and simply goes from 6 to 12.
Thanks in advance for any tips, and any ideas on how I could simplify this code would be appreciated.
채택된 답변
Adam Danz
2021년 2월 12일
My guess
set(gca,'xticklabel',x)
should be
set(gca,'xtick',x)
If not, we need more info.
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Axis Labels에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!