functions within the script
Afficher commentaires plus anciens
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 commentaires
Akshit Bagde
le 27 Juin 2021
If you are writing a script file which contains both commands and function definitions, the functions must be placed at the end of the file. Read about it here - Declare Functions in MATLAB.
Rashid Hussein
le 27 Juin 2021
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 27 Juin 2021
1 vote
Put the script first, not after the function. And make sure the function ends with an "end" statement.
1 commentaire
Rashid Hussein
le 27 Juin 2021
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!