Trying to create an interpolation function where Matlab asks me for value inputs.
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Jan
am 12 Nov. 2021
Bearbeitet: Jan
am 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 Kommentare
Jan
am 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
Siehe auch
Kategorien
Mehr zu Downloads finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!