[英]Getting multiple outputs of a function in Matlab
I use a function which may return outputs more than 3 or 4 which makes it hard to assign those numbers / matrices to user defined variables one by one. 我使用的函数可能返回超过3或4的输出,这使得很难将这些数字/矩阵一一分配给用户定义的变量。 Here is the example:
这是示例:
k = fix(log2(length(s)))
[c,l] = wavedec(s,k,'db1');
[cd1,cd2,cd3, ... , cdk] = detcoef(c,l,1:k);
k is 22 in this example. 在此示例中,k为22。 How can I get those outputs by not writing all cd's from 1 to 22?
如何通过不写从1到22的所有cd来获得这些输出?
Don't create those dynamic variables. 不要创建那些动态变量。 Just use:
只需使用:
D = detcoef(c,l,1:k);
This will create a cell array having the same contents as of cd1
, cd2
, ..., cdk
at its 1st, 2nd, ..., kth index respectively. 这将创建一个单元数组,其第一个索引,第二个索引,...,第k个索引的内容分别与
cd1
, cd2
,..., cdk
相同。 Access them using D{1}
, D{2}
,..., D{k}
respectively. 分别使用
D{1}
, D{2}
,..., D{k}
访问它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.