Trying to create an interpolation function where Matlab asks me for value inputs.

3 visualizaciones (últimos 30 días)
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

Respuestas (1)

Jan
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
Kevin Burke
Kevin Burke el 12 de Nov. de 2021
Yeah I get that but I was just wondering if there is anyway to wite s script that would promt matlab to ask me for the input values, rather than me just typing them all in like that. For example, when I run the program, I want dialog to appear asking for X and I can just type the number, then a dialog to appear asking for X1 and so on. Obviously your method works but I was looking for a more user-friendly program if thats possible. Thanks.
Jan
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

Iniciar sesión para comentar.

Categorías

Más información sobre Interpolation en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by