Question about functions in MATLAB
Ältere Kommentare anzeigen
What is the difference between this code
function result = square(n)
result = n*n;
end
and this code
number = 4;
numberSquared= square(number);
disp(numberSquared);
Like I'm confused about the first code specifically. Are both the codes doing the same thing or is there a difference?
Akzeptierte Antwort
Weitere Antworten (1)
shaik faraz
am 8 Apr. 2022
0 Stimmen
upper one is a function
lower one is a script
script only gets you result if u run that particular script
but function can be called from other scripts
Kategorien
Mehr zu Language Support finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!