Effacer les filtres
Effacer les filtres

Creating equally spaced x axis on plot function

8 vues (au cours des 30 derniers jours)
Jake keogh
Jake keogh le 11 Fév 2021
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.
  1 commentaire
Rik
Rik le 11 Fév 2021
Without your data it is hard to reproduce this issue.

Connectez-vous pour commenter.

Réponse acceptée

Adam Danz
Adam Danz le 12 Fév 2021
My guess
set(gca,'xticklabel',x)
should be
set(gca,'xtick',x)
If not, we need more info.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by