我在代码中按照以下方式对全局变量进行操作。我想将每次保存到全局变量并保留其内容以便扩展。如果我声明函数的输出是这个变量,如果结构很大,我假设它可能会显着减慢。怎么做?
function test()
global n1;
n1 = [1 2 3];
for x=1:10
% [n1] = global_up(n1,x); % no need for output parameter, as n1 is global right?
f_up(n1,x);
end
end
function f_up(arg1,arg2) %function [arg1] = f_up(arg1,arg2) is wrong?
global n1; % need to write it in every function ?
arg1 = [arg1 arg2];
end