我想澄清如何控制从 matlab 中的函数返回变量,例如让我们考虑这段代码
function [x y z]=percentage(a)
n=length(a);
maximum=0;
minimum=0;
subst=0;
minus=0;
plus=0;
minus_perc=0;
plus_perc=0;
for i=1:1:n
if a(i)>0
plus=plus+1;
else
minus=minus+1;
end
end
minuc_perc=minus/n;
plus_perc=plus/n;
maximum=max(minus_perc,plus_perc);
minimum=min(minus_perc,plus_perc);
subst=maximum-minimum;
x=plus_perc;
y=minus_perc;
z=subst*100;
if plus_perc>minus_perc
disp('among the successful people,relevant propession was choosen by');
disp(z)
disp('% people');
else
disp('among the successful people,irrelevant propession was choosen by');
disp(z);
disp('% people');
end
end
我想要返回的是plus_proc
,min_proc
并且subst
,但是当我运行以下命令时,得到这样的结果
[c d e]=percentage(a)
among the successful people,relevant propession was choosen by
58.3333
% people
c =
0.5833
d =
0
e =
58.3333
所以我认为有问题,数组是这样的
a =
1 -1 1 1 -1 1 -1 -1 1 1 1 -1
所以又来了,我想回来plus_proc
,,minus_proc
和subst