specifying the ydata for imagesc

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 commentaire

Adi Natan
Adi Natan le 3 Mar 2012
you may want to try xyimagesc.m
(see the file exchange: http://www.mathworks.com/matlabcentral/fileexchange/32732-xyimagesc-m )

Connectez-vous pour commenter.

Réponses (3)

bym
bym le 10 Juin 2011

0 votes

perhaps:
imagesc(X,log(Y),M) %or whatever your mapping is

1 commentaire

Leon
Leon le 10 Juin 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)

Connectez-vous pour commenter.

Walter Roberson
Walter Roberson le 10 Juin 2011

0 votes

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 le 8 Jan 2020
Modifié(e) : Martin Kahn le 8 Jan 2020

0 votes

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.

Catégories

Tags

Question posée :

le 10 Juin 2011

Modifié(e) :

le 8 Jan 2020

Community Treasure Hunt

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

Start Hunting!

Translated by