Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Change axis 'value' lables

Subject: Change axis 'value' lables

From: Zeph Davies

Date: 30 Oct, 2009 13:44:02

Message: 1 of 3

Hi

I have a surface I'm plotting using a n by m matrix filled with data from a similar matrix in a text file.

Currently the axis values are x=1:n, y=1:m and z is the minimum to maximum matrix value.

However i would like the axis to read an arbitrary range rather that 1:n, for example, 200 to 2500 in steps of 100, or 20 to 10 (ie reversed), without changing the surface, only the axis values.

Changing the limits only changes where you look, pushing the graph out of bounds.

How do i go about achieving this?

Many thanks.

Subject: Change axis 'value' lables

From: Steven Lord

Date: 30 Oct, 2009 14:23:33

Message: 2 of 3


"Zeph Davies" <maylab@zephmail.co.uk> wrote in message
news:hceqj2$amu$1@fred.mathworks.com...
> Hi
>
> I have a surface I'm plotting using a n by m matrix filled with data from
> a similar matrix in a text file.
>
> Currently the axis values are x=1:n, y=1:m and z is the minimum to maximum
> matrix value.
>
> However i would like the axis to read an arbitrary range rather that 1:n,
> for example, 200 to 2500 in steps of 100, or 20 to 10 (ie reversed),
> without changing the surface, only the axis values.
>
> Changing the limits only changes where you look, pushing the graph out of
> bounds.
>
> How do i go about achieving this?

Two options off the top of my head:

1) Call SURF with three inputs (X, Y, and Z) instead of just one (Z) -- as
the documentation says, if you call it with just Z it uses 1:size(Z, 2) for
the X coordinates and 1:size(Z, 1) for the Y coordinates.

2) Use the SET function to change the XTickLabel and YTickLabel properties
of the axes. For your reversed limits, the XDir and YDir properties may
also be useful. You will need the handle to the axes to do this; either
calling AXES with an output argument before creating your surface plot or
using GCA should do the trick.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Subject: Change axis 'value' lables

From: Zeph Davies

Date: 30 Oct, 2009 14:49:02

Message: 3 of 3

"Steven Lord" <slord@mathworks.com> wrote in message <hcesri$1al$1@fred.mathworks.com>...
>
> "Zeph Davies" <maylab@zephmail.co.uk> wrote in message
> news:hceqj2$amu$1@fred.mathworks.com...
> > Hi
> >
> > I have a surface I'm plotting using a n by m matrix filled with data from
> > a similar matrix in a text file.
> >
> > Currently the axis values are x=1:n, y=1:m and z is the minimum to maximum
> > matrix value.
> >
> > However i would like the axis to read an arbitrary range rather that 1:n,
> > for example, 200 to 2500 in steps of 100, or 20 to 10 (ie reversed),
> > without changing the surface, only the axis values.
> >
> > Changing the limits only changes where you look, pushing the graph out of
> > bounds.
> >
> > How do i go about achieving this?
>
> Two options off the top of my head:
>
> 1) Call SURF with three inputs (X, Y, and Z) instead of just one (Z) -- as
> the documentation says, if you call it with just Z it uses 1:size(Z, 2) for
> the X coordinates and 1:size(Z, 1) for the Y coordinates.
>
> 2) Use the SET function to change the XTickLabel and YTickLabel properties
> of the axes. For your reversed limits, the XDir and YDir properties may
> also be useful. You will need the handle to the axes to do this; either
> calling AXES with an output argument before creating your surface plot or
> using GCA should do the trick.
>
> --
> Steve Lord
> slord@mathworks.com
> comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
>

Finally got it, thank you!
See Below:

% Read First Line
[xmin xmax xstep ymin ymax ystep] = textread(FileName, '', 1, 'delimiter', '\t')
% Read Following Matrix
Z = textread(FileName, '', -1, 'headerlines', 1, 'delimiter', '\t');
for i = 0:(xmax-xmin)/xstep
  X(i+1) = xmin+i*xstep;
end
for i = 0:(ymax-ymin)/ystep
  Y(i+1) = ymin+i*ystep;
end
% Plot Graph
surf(X,Y,Z);

Works great. However i had another error where i had "training tabs" at the end of each line of the matrix in the file. Solved with a if statement to not print a tab if last value.

Thank you again!

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us