Trying to create an interpolation function where Matlab asks me for value inputs.
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Jan
on 12 Nov 2021
Edited: Jan
on 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 Comments
Jan
on 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
See Also
Categories
Find more on Downloads in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!