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

1 Ansicht (letzte 30 Tage)
Isa Duran
Isa Duran am 10 Mär. 2016
Kommentiert: Chris Turnes am 10 Mär. 2016
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

Akzeptierte Antwort

Chris Turnes
Chris Turnes am 10 Mär. 2016
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 Kommentare
Isa Duran
Isa Duran am 10 Mär. 2016
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
Chris Turnes am 10 Mär. 2016
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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by