简体   繁体   English

键入几个varargin参数

[英]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. 我有一个使用varargin作为输入的函数,但是当我必须调用此函数时,我创建了多个矩阵,并且在命令窗口中键入所有矩阵的效率非常低。

First I use a function that creates, for example, 50 2x2 matrices. 首先,我使用一个函数来创建例如50个2x2矩阵。 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)) 当我不得不使用另一个函数时,我必须一个一个地调用,例如: 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...) 诸如rich(A(:,:,1:50) or rich(A(:,:,1):A(:,:,50)) (我知道这是不可能的,但我一直在寻找类似的东西这个...)

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{:})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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