MATLAB Answers

Calling a function from a script

265 views (last 30 days)
Kyle Donk
Kyle Donk on 17 Jan 2020
Commented: Stephen on 18 Jan 2020
I'm trying to call a function from a script, but everything that I have seen and read on how to do so has not been helpful. Would someone please show me an example of calling a function from a script? I would really appreciate it.
  2 Comments
Stephen
Stephen on 18 Jan 2020
Kyle Donk's "Answer" moved here:
Yes, it's in the same file, just a different script.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 18 Jan 2020
Example of calling a function from a script:
x = input('Input x ');
y = xsquared(x);
disp(y)
function y = xsquared(x)
y = x.*x;
end
  2 Comments
Walter Roberson
Walter Roberson on 18 Jan 2020
Earlier versions would require that the function be stored in a separate file.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!