specifying the ydata for imagesc
10 views (last 30 days)
Show older comments
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
on 3 Mar 2012
you may want to try xyimagesc.m
(see the file exchange: http://www.mathworks.com/matlabcentral/fileexchange/32732-xyimagesc-m )
Answers (3)
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).
0 Comments
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.
0 Comments
See Also
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!