简体   繁体   中英

Typing several varargin arguments

I have a function that uses varargin as its input, but when I have to call this function, I create several matrices, and it's very inefficient to type all of them on the command window.

First I use a function that creates, for example, 50 2x2 matrices. And when I have to use this other function, I have to call one by one, for example: rich(A(:,:,1), A(:,:,2), (...), A(:,:,50))

Is there a easiest way to call these matrices without the need to type one by one? Something like rich(A(:,:,1:50) or rich(A(:,:,1):A(:,:,50)) (I know this is not possible, but I was looking for something like this...)

Try this:

%# random matrix of size 2x2x50
A = rand(2,2,50);

%# split by slices along the third dimension: AA = {A(:,:,1); ...; A(:,:,50)}
AA = mat2cell(A, 2, 2, ones(1,size(A,3)));
AA = AA(:);

%# call function, expanding into a comma-separated list
rich(AA{:})

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