How can I interpolate with a Matrix and a Vector to another vector?

11 views (last 30 days)
Hi there,
I have the following data in MATLAB, as two vectors (Temperature and Concentration) and one matrix (Enthalpy):
Capture.PNG
I use the following code to get a value within the Enthalpy matrix using both vectors:
interp2(Temperature,Concentration,Enthalpy,10,5)
ans = 37,22
Thats ok; Now I would like to get a value within Temperature Vector using the Concentration Vector and the Enthalpy Matrix as:
interp2(Concentration,Enthalpy,Temperature,55.58,88.6199)
which should give a value between 30°C and 40°C, but I get:
Error using griddedInterpolant
The number of input coordinate arrays does not equal the number of dimensions (NDIMS) of these arrays.
Error in interp2>makegriddedinterp (line 228)
F = griddedInterpolant(varargin{:});
Error in interp2 (line 136)
F = makegriddedinterp(X, Y, V, method,extrap);
Im little new using MATLAB, it surely shall be a dimension problem when I trying interpolate using a matrix and vector.
If anyone has any idea how to this, any help would be greatly appreciated.
Kind regards,
José C.

Accepted Answer

KSSV
KSSV on 20 Aug 2019
YOu see, you cannot use Enthalpy as you have used, because it is not a valid meshgrid. Reather, you can treat the data as scattered data and use to get the values you want. Check the below demo code.
[X,Y,Z] = peaks(100) ;
val1 = interp2(X,Y,Z,3,3) ; % this works; X, Y are valid meshgrid
% val2 = interp2(X,Z,Y,3,val1) ; % this doesnot work; Z is not a avalid grid
F = scatteredInterpolant(X(:),Z(:),Y(:)) ;
val2 = F(3,val1) ;

More Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!