specifying the ydata for imagesc

10 views (last 30 days)
Leon
Leon on 10 Jun 2011
Edited: Martin Kahn on 8 Jan 2020
I am trying to create an image of a matrix M in which the rows represent specific frequency values, the colums are time points and the values of the matrix (the cdata of the image) are the power at each time and frequency (in other words, it is a spectrogram). I have a vector Y of frequencies which describe the rows, and a vector X describing the times.
I use: imagesc(X,Y,M)
For good reasons, the values in my Y are not evenly distributed between Y(1) and Y(end). Matlab on the other hand ingores everything except Y(1) and Y(end) and assumes that the Y axis is evenly distributed bween the two. As a result, using e.g. 'ginput', or the data cursor tool to sample the image does not return the correct value of the Y axis (i.e., the correct frequency of that row in the matrix).
This behavior of ignoring everything but the start and end of Y is documented in the 'imagesc' help document, so it is a feature, not a bug, but it is annoying. I wonder if I a missing a way to get beyond this imiitation.
Thanks,
Leon
  1 Comment
Adi Natan
Adi Natan on 3 Mar 2012
you may want to try xyimagesc.m
(see the file exchange: http://www.mathworks.com/matlabcentral/fileexchange/32732-xyimagesc-m )

Sign in to comment.

Answers (3)

bym
bym on 10 Jun 2011
perhaps:
imagesc(X,log(Y),M) %or whatever your mapping is
  1 Comment
Leon
Leon on 10 Jun 2011
Thanks. The problem is that Matlab ignores whatever you put for Y, except its first and last element. So for instance Y = [2,4,8,16] and Y = [2,7,11,16] yield the same thing, both not reflecting the Y argument in the command. Try the following for example. You will get two similar images, and using the data cursor doesn't return the intended values in either one.
Leon
A = rand(4,10);
Y1 = [2,4,8,16];
Y2 = [2,7,11,16];
X = 1:10;
figure
subplot(2,1,1)
imagesc(X, Y1,A)
subplot(2,1,2)
imagesc(X, Y2,A)

Sign in to comment.


Walter Roberson
Walter Roberson on 10 Jun 2011
For the data cursor, use a custom data cursor formatting function and map the linear y to the nearest desired Y (or an interpolation of it).

Martin Kahn
Martin Kahn on 8 Jan 2020
Edited: Martin Kahn on 8 Jan 2020
Seeing that this question still gets views despite its age:
One way of doing this is using surface(X,Y,Z) instead of imagesc. Don't forget to set the shading (i.e. shading flat;). To me it seems the Matlab documentation on this should be much clearer that imagesc simply can't do this.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!