How to save variables in a function to the workspace
33 次查看(过去 30 天)
显示 更早的评论
i want to save the variables( x , y , z , xx , yy) in a function to the workspace.
**************************************
global x
global y
global z
global xx
global yy
test(1,2,3)
function test(x,y,z)
x
y
z
x+y+z
test2(4,2)
end
function test2(xx,yy)
xx
yy
xx-yy
end
采纳的回答
Cris LaPierre
2021-2-12
Don't use globals. Return your variables through the function output. See the documentation. This example from that page shows how to return the variable ave.
myave = average([1:10])
% function declaration
function ave = average(x)
ave = sum(x(:))/numel(x);
end
9 个评论
Stephen23
2021-2-13
@Hiroyasu Fujita: how to call functions with one or more outputs is explained here:
Those tutorials explain many basic concepts that you will need to know if you want to use MATLAB.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Phased Array System Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!