How to call the rows of a matrix without the for loop
7 views (last 30 days)
Show older comments
Hi I have a matrix A=[1 2 3 4 5;6 7 8 9 10; 11 12 13 14 15] and I want to call each row of the matrix one by one as an input to my program. i.e, A(1,:) is taken as first input, A(2,:) is the second input and finally A(3,:), just like it is done in a loop, but is there any way that I can do the same without using a for loop.
Any help would be much appreciated.
1 Comment
Fangjun Jiang
on 12 Dec 2017
Do you want MyFun(A(1,:),A(2,:),A(3,:)), or MyFun(A(1,:)), MyFun(A(2,:)), MyFun(A(3,:))? How do you plan to do it using for-loop?
Accepted Answer
KL
on 12 Dec 2017
Probably convert them to cell array and then the use of comma-separated lists,
B = num2cell(A,2)
and then
your_program(B{:})
3 Comments
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!