Using the global operator
2 次查看(过去 30 天)
显示 更早的评论
I have a function below.
As you can see if t==1 I create a vector kk. However, I can not use this kk in the 'else' statement unless I use 'global kk''. Is that correct?
function [ll mm]= ssample(e2,t)
global kk
if t==1
kk=zeros(T,1);
for s=1:T
kk(s) =...;
end
else
for s=t:T
ll =kk(s) ;
end
end
mm=kk;
end
5 个评论
Walter Roberson
2019-5-9
We would need the calling code to be sure that t starts at 1.
Better to avoid the matter, such as the way Matt suggests.
采纳的回答
Matt J
2019-5-9
No, you should not use global. Your code should look like this:
function [ll, mm, kk]= ssample(e2,t,kk)
...
end
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!