Filter löschen
Filter löschen

Creating equally spaced x axis on plot function

8 Ansichten (letzte 30 Tage)
Jake keogh
Jake keogh am 11 Feb. 2021
Beantwortet: Adam Danz am 12 Feb. 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 Kommentar
Rik
Rik am 11 Feb. 2021
Without your data it is hard to reproduce this issue.

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

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

Weitere Antworten (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by