Trying to create an interpolation function where Matlab asks me for value inputs.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
What am I doing wrong and how can I make this function work? I am a beginner to matlab. Thanks!
function[Y] = Interpolation (X,x1,x2,y1,y2)
Y=(y1 + (X-x1)*((y2-y1)/(x2-x1)))
X=input('X:')
x1=input('x1:')
x2=input('x2:')
y1=input('y1:')
y2input('y2:')
end
0 comentarios
Respuestas (1)
Jan
el 12 de Nov. de 2021
Editada: Jan
el 12 de Nov. de 2021
function Y = Interpolation (X,x1,x2,y1,y2)
Y = y1 + (X-x1) * (y2-y1) / (x2-x1);
end
Now provide the input arguments as inputs of a function:
Y = Interpolation(2.3, 2, 3, 1.5, 2.5)
Providing inputsdoes not mean to call the function input().
With pressing the green triangle, the current function is called without input arguments. The produces the error message.
2 comentarios
Jan
el 13 de Nov. de 2021
@Kevin Burke: Providing inputs to functions is much more convenient than input() comands in the show case: if you want to repeat a calculation, you can simply repeat the call, e.g. by copy&past. Wit input() you have to type in all variables again. For number woth 16 digits this is tedious. But of course it works:
function Y = Interpolation() % No input arguments here
X = input('X:')
x1 = input('x1:')
x2 = input('x2:')
y1 = input('y1:')
y2 = input('y2:')
Y = y1 + (X-x1) * (y2-y1) / (x2-x1);
end
For GUIs see:
doc appdesigner
Ver también
Categorías
Más información sobre Interpolation en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!