Question about functions in MATLAB
显示 更早的评论
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?
采纳的回答
更多回答(1 个)
shaik faraz
2022-4-8
0 个投票
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
类别
在 帮助中心 和 File Exchange 中查找有关 Language Support 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!