Converting single column matrix into array with condition
1 view (last 30 days)
Show older comments
Hey,
I want to convert 2701x1 vector matrix into 73x73,
condition: it should jump to next row when index value is equal to 1
for e.g:
a = [1,3,1,2,3,4,1,4,5,6]
so we should get output "c" as:
c =
1,3 ;
1 2 3 4 ;
1 4 5 6
so it is should jump to new row when index value is equal to 1, kindly help?
0 Comments
Answers (1)
Walter Roberson
on 18 Feb 2017
c = mat2cell(a, 1, diff([find(a == 1), length(a)+1]) ) .'
Note that you cannot do this as a plain numeric array, since numeric arrays cannot have rows of different sizes
2 Comments
Walter Roberson
on 19 Feb 2017
c = mat2cell(a.', 1, diff([find(a.' == 1), length(a)+1]) ) .'
See Also
Categories
Find more on Matrix Indexing 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!