MATLAB Answers

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

17 views (last 30 days)
José Cabrera
José Cabrera on 20 Aug 2019
Answered: KSSV on 20 Aug 2019
Hi there,
I have the following data in MATLAB, as two vectors (Temperature and Concentration) and one matrix (Enthalpy):
I use the following code to get a value within the Enthalpy matrix using both vectors:
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:
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.


Sign in to comment.

Accepted Answer

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) ;


Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by