Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MATLAB imagesc command not working for non-evenly spaced y-axis values [duplicate]

Tags:

plot

image

matlab

Ok, so this is starting to get very frustrating.

I have the following code: (scannedResponse, thetaAxis given here).

clear all
load scannedResponse
load thetaAxis
figure(1); clf(1);
pcolor(1:size(scannedResponse,2), thetaAxis, scannedResponse); shading interp; 
figure(2); clf(2);
imagesc(1:s.N.Lsnaps, (thetaAxis),  scannedResponse);

So I get two images. One made with pcolor, and one made with imagesc. The pcolor image is correct, because the y-axis is correct, and the lines are where they are supposed to be. The imagesc is wrong, because the y-axis is wrong, and the lines are not where they are supposed to be.

enter image description here

enter image description here

As you can see, the lines of the imagesc image do not agree with the lines of the pcolor image. I cannot seem to get the imagesc y-axis to agree with the pcolor y-axis, and thus give me a similar plot. How do I go about doing that?

P.S. I have already tried the full gamut of flipping the y-axis for imagesc, using the set(gca,'Ydir', 'normal') command, etc etc to no avail.

Thanks.

like image 915
Spacey Avatar asked Dec 22 '25 05:12

Spacey


1 Answers

The problem is that thetaAxis contains non-equally spaced values. pcolor can deal with that, imagesc can't. A solution is to interpolate your data to get them on an equally spaced grid:

% determine interpolation grid: from min to max in equal steps
intpoints = linspace(min(thetaAxis), max(thetaAxis), numel(thetaAxis));
% interpolate the data to fit the new "axis"
int = interp1(thetaAxis', scannedResponse, intpoints);
% plot the interpolated data  using the new "axis"
imagesc(1:size(scannedResponse,2), intpoints, int)
% revert the direction of the y axis
axis xy

Except for the implicit smoothing that pcolor appears to do, this plot looks identical to the one using pcolor(1:size(scannedResponse,2), thetaAxis, scannedResponse); shading interp.

like image 86
A. Donda Avatar answered Dec 23 '25 21:12

A. Donda