MATLAB Answers

Plotting using x-axis arrays that are not in monotonically increasing order?

13 views (last 30 days)
My goal is to plot a curtain profile using imagesc() with the x-axis corresponding to the Latitude values and y-axis to the Altitude. My x-axis data are the latitude points of an instrument orbiting the Earth. In this scenario, the latitude values increase (reaching top of orbit) and then they decrease.
I've been able to successfully plot these profiles for when the latitude values were in increasing/decreasing order but not when they have both scenarious occuring.
Anyone have an idea/code that can fix this error? Thank you!
x = latitude;
y = altitude;
z = data; % (in matrix format)
imagesc(x, y, z)
%Error: x vector must be in increasing order%

  3 Comments

Cris LaPierre
Cris LaPierre on 9 Mar 2019
Easier to play with actual data. Can you upload a mat file with your x, y, and z data?
Natasha D
Natasha D on 11 Mar 2019
Unfortunately the data exceeds the upload size.
I tried pcolor but it isn't giving me what I want it to. Thank you though.

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 9 Mar 2019
Edited: Cris LaPierre on 20 Mar 2019
Is your x vector evenly sampled? Without having actual data, my suggestion would be make x=1:length(latitude) and plot that. Then update your xTickLabels to be the actual latitude values.

  3 Comments

srt10
srt10 on 21 Jan 2021
How would you do this if the vector isn't evenly sampled? For example I have a vector that corresponds to Wavelength that I obtained from a evenly spaced frequency vector. If I want to plot my spectrum vs wavelength in an imagesc plot, I run into problems where the image is flipped because the wavelength vector is decreasing and is also not evenly sampled
Cris LaPierre
Cris LaPierre on 22 Jan 2021
The underlying ruler is going to be evenly spaced and monotonically increasing. This is what is used to place your X and Y values.
Imagesc is slightly different in that it uses the row indices as the Y values, and the column indices as the X values. If you want to change the 'direction', you must manipulate the matrix. Perhaps try using fliplr to reverse the x direction, of flipud to revers the y direction.
Walter Roberson
Walter Roberson on 22 Jan 2021
You would not typically need to fliplr or flipud for imagesc. However you might want to
set(gca, 'YDir', 'normal')
The default for imagesc() is YDir reverse, so that data in the low Y indices (lower row) is shown at the top of the display and higher Y indices (higher row) is at the bottom of the display.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!