X-axis Labeling

2 Ansichten (letzte 30 Tage)
Stefan Azzopardi
Stefan Azzopardi am 19 Apr. 2018
Beantwortet: Wick am 2 Mai 2018
Hi,
I am a new user of MATLAB. I managed to read a large excel sheet on Matlab, sorted the data and plotted the graph of the wanted data. The problem that I am experiencing is that I am trying to make the values of x-axis as a percentage. I have a variable of around 1000 integer which may increase as I add data. I have assigned a variable to check the length of variable so that I do not have to change it manually. The problem is that I need to assign the x-axis in terms of 10%, 20%... 100%. How can I do that without reducing data for the y-axis?
Regards
  1 Kommentar
Stefan Azzopardi
Stefan Azzopardi am 19 Apr. 2018
The following is the code for the x-axis
A=round(length(data),2,'significant');
d=0.1*A
e=0:d:A
f=e/A*100
set(gca,'xticklabel', f)
The x-axis is showing up till 90%. The length of 'data' is 16990, therefor A results in 17000. d results to be 1700. Value of f is from 0 to 100 but the plot is still showing to 90%

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Wick
Wick am 2 Mai 2018
I think the problem has to do with the fact that when there are 1000 elements in an array, there are only 999 gaps between those values. So the way you're constructing things nothing ever ends up at eactly 100.
Does this do what you want?
x = 100*(0:(length(data)-1)) / (length(data)-1);
plot(x,data)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by