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

3 vues (au cours des 30 derniers jours)
Kevin Burke
Kevin Burke le 12 Nov 2021
Commenté : Jan le 13 Nov 2021
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

Réponses (1)

Jan
Jan le 12 Nov 2021
Modifié(e) : Jan le 12 Nov 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 commentaires
Kevin Burke
Kevin Burke le 12 Nov 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 le 13 Nov 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

Connectez-vous pour commenter.

Catégories

En savoir plus sur Downloads dans Help Center et File Exchange

Produits


Version

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by