2013-09-29 72 views
3

好的,所以这开始变得非常令人沮丧。MATLAB imagesc命令不适用于非均匀间隔的y轴值

我有以下代码:(scannedResponsethetaAxis这里给出)。

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); 

所以我得到两个图像。一个用pcolor制作,另一个用imagesc制作。 pcolor图像是正确的,因为y轴是正确的,并且行是它们应该是的地方。 imagesc是错误的,因为y轴是错误的,线不是它们应该在的地方。

enter image description here

enter image description here

正如你所看到的,于imagesc图像的行不,令pColor图像的行同意。我似乎无法让imagesc y轴与pcolor y轴一致,从而给我一个类似的情节。我该如何去做呢?

P.S.我已经尝试使用set(gca,'Ydir', 'normal')命令等来翻转imagesc的y轴的全部范围,但无济于事。

谢谢。

回答

9

问题是thetaAxis包含非等间隔的值。 pcolor可以处理,imagesc不能。一个解决办法是内插你的数据,让他们在等间隔的网格:

% 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 

除外令pColor用来做隐式平滑,这个阴谋看起来与使用pcolor(1:size(scannedResponse,2), thetaAxis, scannedResponse); shading interp之一。

+0

啊!神奇的Donda。是的,似乎非等间距的值是问题所在。所以问题是,你在插入,但不改变thetaAxis向量的长度是吗?您只是在thetaVec的均匀间隔的新值上找到新的scannedResponse值? – Spacey

+0

对,我做了这样的值的数量保持不变。当然这不一定是最佳的;或者,您可以选择间距,使其与原始“轴”中的最小间距相对应。 –

+0

天才!非常感谢! :D – Spacey