MATLAB Answers

0

How to interpolate for given inputs in a n*m matrix

Isa Duran さんによって質問されました 2016 年 3 月 10 日
最新アクティビティ Chris Turnes
さんによって コメントされました 2016 年 3 月 10 日
Hi there! I have spent hours and hours on the issue which seems to be so easy. I have a m*n matrix: Windspeed (Uw) collums and Wave height (Hs) rows. Uw = [1.12 2.45 4.4 6.7 9.35 12.3]; Hs = [4.9573 6.6098 8.2622 9.9147 13.2196 16.5245 24.7868 33.0490]
For these I have a RPM matrix, so for a given Uw and Hs there is a corresponding RPM. The matrix is like this:
RPM = 65.6515 65.7910 65.9395 66.0283 66.0614 66.2256 73.8276 73.9451 74.0549 74.1204 74.1447 74.2657 82.8548 82.9509 83.0531 83.1140 83.1367 83.2492 91.5963 91.6809 91.7707 91.8243 91.8442 91.9431 106.0902 106.1693 106.2533 106.3034 106.3221 106.4144 117.1710 117.2354 117.3038 117.3446 117.3597 117.4349 133.4657 133.5493 133.6380 133.6909 133.7106 133.8081 144.2077 144.2695 144.3352 144.3743 144.3888 144.4609
So lets say for Hs = 4.9573 and Uw=1.12 RPM is 65.6515. What I want to do is give Hs and Uw as an input so I can find a corresponding RPM in the range mentioned above. example what is RPM if Hs = 8 and Uw = 7 ?
Thanks in advance! Hope my problem is clear enough otherwise feel free to ask me!
Best regards Isa

  0 件のコメント

サインイン to comment.

1 件の回答

Chris Turnes
回答者: Chris Turnes
2016 年 3 月 10 日
 採用された回答

If I understand your question correctly, it sounds like griddedInterpolant is what you're looking for. Here's a small example based on the inputs you gave:
>> % Define wind speed
>> Uw = [1.12 2.45 4.4 6.7 9.35 12.3];
>> % Define wave height
>> Hs = [4.9573 6.6098 8.2622 9.9147 13.2196 16.5245 24.7868 33.0490];
>> % Define RPM, reshape it to be length(Uw) by length(Hs)
>> RPM = reshape([65.6515 65.7910 65.9395 66.0283 66.0614 66.2256 73.8276 73.9451 74.0549 74.1204 74.1447 74.2657 82.8548 82.9509 83.0531 83.1140 83.1367 83.2492 91.5963 91.6809 91.7707 91.8243 91.8442 91.9431 106.0902 106.1693 106.2533 106.3034 106.3221 106.4144 117.1710 117.2354 117.3038 117.3446 117.3597 117.4349 133.4657 133.5493 133.6380 133.6909 133.7106 133.8081 144.2077 144.2695 144.3352 144.3743 144.3888 144.4609], length(Uw), []);
>> % Make a 2-D grid from the wind speed and wave height values to build the interpolant with
>> [U,H] = ndgrid(Uw,Hs);
>> % Build the interpolant
>> F = griddedInterpolant(U,H,RPM);
>> % Interpolate the RPM for a wind speed of 8 and a wave height of 7
>> F(8,7)
ans =
76.2559
Of course, there are many different options to griddedInterpolant, so you should choose whichever is appropriate for your problem.

  2 件のコメント

Isa Duran 2016 年 3 月 10 日
Hi! Thanks a lot!!! We are almost there! I think the print is misguiding you its my fault! But RPM is already shaped like a 8x6 matrix correspond to Hs rows and Uw collums. How will the code look then?
Isa
Chris Turnes
2016 年 3 月 10 日
It will look exactly the same, you just don't need the reshape call. I just needed it to be the right shape to give you the example.
Really, the important part of this code is the group of lines
>> [U,H] = ndgrid(Uw,Hs);
>> % Build the interpolant
>> F = griddedInterpolant(U,H,RPM);
>> % Interpolate the RPM for a wind speed of 8 and a wave height of 7
>> F(8,7)
ans =
76.2559
This is what is setting up the grid and the interpolant, and then interpolating the result.

サインイン to comment.



Translated by