Error in execution?

clear
clc
x=[0 2 4 6 8];
y=[0 2 4 6 8];
T=[100 90 80 70 60; 85 64.49 53.50 48.15 50; 70 48.90 38.43 35.03 40; 55 38.78 30.39 27.07 30; 40 35 30 25 20];
x_target=4;
y_target=3.2;
*T_target=interp2(x,y.T,x_target,y_target)*
When I run this code it gives an error in the last line? Not sure why? Any help is much appreciated!

1 comentario

Masooma Tahir
Masooma Tahir el 6 de Nov. de 2016
I tried the changes you said but still same error T_target=interp2(x,y,T,x_target,y_target)
Error in ex3 (line 12) T_target=interp2(x,y,T,x_target,y_target)

Iniciar sesión para comentar.

Respuestas (3)

Geoff Hayes
Geoff Hayes el 6 de Nov. de 2016
Editada: Geoff Hayes el 6 de Nov. de 2016

0 votos

Masooma - you have a period separating the y and the T rather than a comma. Just change your last line to
T_target=interp2(x,y,T,x_target,y_target)
and try again!

2 comentarios

Masooma Tahir
Masooma Tahir el 6 de Nov. de 2016
I tried the changes you said but still same error T_target=interp2(x,y,T,x_target,y_target) Error in ex3 (line 12) T_target=interp2(x,y,T,x_target,y_target)
Geoff Hayes
Geoff Hayes el 6 de Nov. de 2016
If I run the code that you have posted and change from the period o the comma, then everything works fine without any errors. I suspect that you haven't posted all of your code or are doing something different without showing it. Please copy and paste the full error message into your question so that we can get an idea as to what the error is.

Iniciar sesión para comentar.

Star Strider
Star Strider el 6 de Nov. de 2016

0 votos

You need to use the griddata function, not interp2:
x=[0 2 4 6 8];
y=[0 2 4 6 8];
T=[100 90 80 70 60; 85 64.49 53.50 48.15 50; 70 48.90 38.43 35.03 40; 55 38.78 30.39 27.07 30; 40 35 30 25 20];
x_target=4;
y_target=3.2;
T_target=griddata(x,y,T,x_target,y_target)
T_target =
44.4580
figure(1)
surfc(x, y, T);
hold on
stem3(x_target, y_target, T_target, '^r', 'MarkerSize',10, 'MarkerFaceColor','r')
hold off
grid on
view([-130 25])
The interp2 function requires that your data be gridded before using the function. The griddata function creates the grid itself.
VBBV
VBBV el 12 de Nov. de 2021
Editada: VBBV el 12 de Nov. de 2021

0 votos

clear
clc
x=[0 2 4 6 8];
y=[0 2 4 6 8];
T=[100 90 80 70 60; 85 64.49 53.50 48.15 50; 70 48.90 38.43 35.03 40; 55 38.78 30.39 27.07 30; 40 35 30 25 20];
x_target=4;
y_target=3.2;
T_target=interp2(x,y,T,x_target,y_target) % delete the . in interp2 and replace it with ,
T_target = 44.4580
Delete the dot. in the interp2 function

Categorías

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 6 de Nov. de 2016

Editada:

el 12 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by