MATLAB Answers

functions within the script

조회 수: 1(최근 30일)
Rashid Hussein
Rashid Hussein 2021년 6월 27일
댓글: Rashid Hussein 2021년 6월 27일
i wanted to call the same function several times but with different variables eachtime in the same script
for example
function [a]=myfunction(r)
a=10*r
end
a=myfunction(5)
a=myfunction(7)
i want when run the script to have all results at once but it shows this error message
Error: File: myhot.m Line: 5 Column: 2
This statement is not inside any function.
(It follows the END that terminates the
definition of the function "myfunction".)
thankyou
  댓글 수: 2
Rashid Hussein
Rashid Hussein 2021년 6월 27일
Thank you sir for answering But I want to call the function in the script not in the command line , so when I run the script it will give me the results If it is possible, can you demonstrate the above example given by me ?

댓글을 달려면 로그인하십시오.

채택된 답변

Stephan
Stephan 2021년 6월 27일
편집: Stephan 2021년 6월 27일
a1=myfunction(5)
a2=myfunction(7)
function a=myfunction(r)
a=10*r
end
  댓글 수: 2
Rashid Hussein
Rashid Hussein 2021년 6월 27일
Thank you sir for your answer , appreciate your efforts

댓글을 달려면 로그인하십시오.

추가 답변(1개)

Image Analyst
Image Analyst 2021년 6월 27일
Put the script first, not after the function. And make sure the function ends with an "end" statement.
  댓글 수: 1
Rashid Hussein
Rashid Hussein 2021년 6월 27일
Thank you sir for your answer, deeply appreciated

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

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

Start Hunting!

Translated by