matlab参数群体赋值,Matlab多变量赋值

我想出了一种方法来做到这一点。感谢Will Robertson的回答,我意识到写一个函数是真正得到我想要的唯一方法。这是分裂。

function [ o1, o2, o3, o4, o5, o6, o7, o8 ] = split( v )

%SPLIT Splits a vector of bounded length into individual return variables.

% Split() can handle arbitrarily long input vectors, but only a fixed

% number of output variables. @benathon

%

% Usage:

% vec = [1 2 3 4 5];

% [a,b,c,d,e] = split(vec);

% [f,g] = split(vec);

% If you would like to upgrade split() to handle more output variables,

% simply add more output variables to the function definition and

% then change this variable

maxout = 8;

[~,n] = size(v);

if n < nargout

error('input vector too short for number of output arguments');

end

% we only need to assign this many output variables

iterations = min(n,nargout);

% Matlab catches "Too many output arguments." before we can

%if( iterations > maxout )

% error('Too many output, edit split.m to easily upgrade');

%end

i = 1;

while i <= iterations

expression = sprintf('o%d=v(%d);', i, i);

eval(expression);

i = i + 1;

end查看注释以了解用法。我还提出了一个要点:https://gist.github.com/esromneb/652fed46ae328b17e104

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值