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
Adam Danz 2021-2-12
My guess
set(gca,'xticklabel',x)
should be
set(gca,'xtick',x)
If not, we need more info.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Axis Labels 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by