Issue in specifying input arguments for interp2 function

5 ビュー (過去 30 日間)
Luca Barbiero
Luca Barbiero 2013 年 12 月 8 日
編集済み: sixwwwwww 2013 年 12 月 8 日
I have some data in specific locations of a matrix, which I need to interpolate. The picture below (which I borrowed here) sketches the problem (only look at the blue P elements with no interest on the groupings).
I am trying to do this by using the interp2 function for 2-D interpolation. However I can't figure out how to specify the input arguments interp2(X, Y, Z, XI, YI). In particular, how should I specify the matrix Z? It should be made of the blue elements only, which are not really uniformly spaced on the grid.
Thanks for any help

回答 (1 件)

sixwwwwww
sixwwwwww 2013 年 12 月 8 日
編集済み: sixwwwwww 2013 年 12 月 8 日
you can do it as follow:
[x, y] = meshgrid(1:20); % Define x-y grid on which z values will be located
z = randi([0 1], 20); % Generating values 0 and 1 on that grid
x1 = randi(20, 20); % generating random locations of x on grid for interplotation
y1 = randi(20, 20); % generating random locations of y on grid for interplotation
z1 = interp2(x, y, z, x1, y1); % getting values of z by interplotation on those random locations
I hope it helps understanding the concept. Good luck!

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by