Sending comma seperated list of vectors to a variable input function
1 view (last 30 days)
Show older comments
Hello all,
I have a function F that can take a variable number of vectors as input. I.E. it can take F(1:4) or F(1:4, 1:3) or F(1:4, 1:3, 1:2) ... etc.
I would like to be able to send it a variable number of inputs from a script. That is, sometimes the script will call it with 3 vectors as input, or sometimes 10 vectors, etc.
I've tried to use mat2cell which I think would work, but I am having trouble formatting it properly, perhaps I do not understand the help page for it.
Say I have a vector B
>> B = [1:4; 1:4; 1:4]
B =
1 2 3 4
1 2 3 4
1 2 3 4
And I want to call F(1:4, 1:4, 1:4). How do I do this?
I've tried
X = mat2cell(X, 3, 4)
and called F(X{:}), but this does not provide the desired output.
If you can provide any help I thank you in advanced!
0 Comments
Accepted Answer
More Answers (1)
Image Analyst
on 15 Jul 2013
Look up varargin. It's whole purpose in life is what you're describing.
2 Comments
Jan
on 15 Jul 2013
As far as I understand, Mark's problem does not concern getting the list of inputs inside the function, but providing a list of inputs from the caller.
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!