Dominique
Dominique

Reputation: 167

MATLAB axes have constant values

I am working on a project which plots deltaL on the y axis and Fnet on the x axis. The script is as follows:

%Variables for delta L
L=518;
E=1040000000;
A=0.0020268;

%Variables for Form Drag
Ad=25.437;
Cd=2.015;
p=999.835;
v=2.02917;

%Array for theta
theta=0:pi/360:pi/45;

Fd=0.5*p*Cd*v^2;

T=(L/2).*tan(theta);

Fnet=sqrt((T.^2)+(Fd.^2));

deltaL=(Fnet.*L)./(E.*A);

plot(Fnet,deltaL,'.');

When I plot the data, the values on the x axis are all the same and the values on the y axis are also the same. The x and y values are different. However, my graph still creates a working model of my data. Is there a piece of my code which is causing this issue or is there some glitch in matlab that can somehow be fixed?

Upvotes: 2

Views: 684

Answers (3)

bla
bla

Reputation: 26069

You are trying to plot values that increase in very small magnitudes vs their initial value. For example if you would instead plot

 plot(Fnet-Fnet(1),deltaL-deltaL(1),'.');

you'll see the relevant numbers that these change by.

A possible solution is to edit the xtick-labels and ytick-labels according to your needs. For Example

    plot(Fnet,deltaL,'.');
    yt=get(gca,'YTick')'
    set(gca,'YTick',yt,'YTickLabel',num2str(yt,'%.6f')); 

enter image description here

Actually, you can do it in a single line! just add:

   set(gca,'YTick',get(gca,'YTick')','YTickLabel',num2str(get(gca,'YTick')','%.6f'));

Upvotes: 1

Andreas H.
Andreas H.

Reputation: 6073

Well, the values on the X and Y are not the same - it is just that Matlab rounds the numbers before displaying to 4 or 5 digits (Which is intended and meaningful behavior). You would need to choose a appropriate data presentation (e.g. use an offset for the X and Y data).

For example

 xofs = round(mean(Fnet)*100)/100;
 yofs = round(mean(deltaL)*10000)/10000;
 plot( Fnet-xofs, deltaL-yofs );
 xlabel( sprintf('Fnet - %0.2f', xofs) );
 ylabel( sprintf('\\DeltaL - %0.4f', yofs) );

Upvotes: 0

Oli
Oli

Reputation: 16035

That is because the precision of the values of x/y axis is not high enough.

You can use the trick from this page: http://www.mathworks.fr/support/solutions/en/data/1-3P8CU0/index.html?product=ML&solution=1-3P8CU0

old_ticks = get(gca, 'ytick')';
new_tick_labels = cellfun(@(x) sprintf('%9.6f',x), num2cell(old_ticks), 'uniformoutput', false);
set(gca, 'yticklabel', new_tick_labels)
old_ticks = get(gca, 'xtick')';
new_tick_labels = cellfun(@(x) sprintf('%9.6f',x), num2cell(old_ticks), 'uniformoutput', false);
set(gca, 'xticklabel', new_tick_labels)

result (right-click + "display image" for a better resolution):

enter image description here

Upvotes: 2

Related Questions