1

I have a matrix with dimension 27x4, now I want to interpolate the matrix and plot it with the same aspect ratio. I've been using interp2 but since it fills in values in between existing ones after each step the matrix grows in both dimension 2*n-1, which results in the height growing faster than the width.

Is there a method to interpolate a matrix filling the new matrix only with interpolated values without the original ones, to say get one with both dimensions doubled?

The only method I could think of, is to interpolate with interp2 to a higher degree and then pick out values, but this would be highly inefficient.

4

1 回答 1

0

interp2应该可以正常工作,它必须是您定义最后 2 个参数的方式。尝试这个:

Z = rand(4,27);
x = 1:27;
y = 1:4;
[X, Y] = meshgrid(x, y)

xi = linspace(1, 27, 1000);
yi = linspace(1, 4, 1000 * (4/27)); % The 4/27 here is what ensures you keep the aspect ratio
[XI, YI] = meshgrid(xi, yi);

ZI = interp2(X,Y,Z,XI,YI);

检查纵横比

size(ZI,1) / size(ZI,2)

ans =

    0.1480

size(Z,1) / size(Z,2)

ans =

    0.1481

但基本上你需要确保的是我上面的代码中的纵横比xiyi你原来的相匹配。也很容易概括。

于 2013-05-09T14:02:26.097 回答