【问题标题】:MATLAB imagesc command not working for non-evenly spaced y-axis values [duplicate]MATLAB imagesc 命令不适用于非均匀间隔的 y 轴值 [重复]
【发布时间】:2014-03-11 10:50:36
【问题描述】:

好的,所以这开始变得非常令人沮丧。

我有以下代码:(scannedResponse, thetaAxis 这里给出)。

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 轴是错误的,并且线条不在它们应该在的位置。

如您所见,imagesc 图像的线条与 pcolor 图像的线条不一致。我似乎无法让 imagesc y 轴与 pcolor y 轴一致,因此给了我一个类似的情节。我该怎么做呢?

附:我已经尝试过使用set(gca,'Ydir', 'normal') 命令等为imagec 翻转y 轴的全部范围,但无济于事。

谢谢。

【问题讨论】:

    标签: image matlab plot


    【解决方案1】:

    问题在于 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 的图相同。

    【讨论】:

    • 啊!了不起的唐达。是的,似乎不等间距的值是问题所在。所以问题,你是插值,但不改变 thetaAxis 向量的长度是吗?您只是在 thetaVec 的新均匀间隔值处找到新的扫描响应值正确吗?
    • 对,我这样做是为了使值的数量保持不变。当然,这不一定是最佳的。或者,您可以选择间距,使其对应于原始“轴”中的最小间距。
    • 天才!非常感谢! :D
    • 最后一个问题,我正在尝试使用 rot90 命令逆时针旋转图像,但是时间轴(从 1 到 100 的那个)没有搞砸......我解决这个?再次感谢。
    • 使用插值图像,旋转它应该没有问题。但你确定要这样做吗?如果你想交换轴,转置' 将是要走的路。
    猜你喜欢
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 2016-12-26
    相关资源
    最近更新 更多