简体   繁体   中英

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. 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. How can I get those outputs by not writing all cd's from 1 to 22?

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. Access them using D{1} , D{2} ,..., D{k} respectively.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM