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

11 vues (au cours des 30 derniers jours)
José Cabrera
José Cabrera le 20 Août 2019
Réponse apportée : KSSV le 20 Août 2019
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.

Réponse acceptée

KSSV
KSSV le 20 Août 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) ;

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by