Converting single column matrix into array with condition

1 view (last 30 days)
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?

Answers (1)

Walter Roberson
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
Hasan Parvez
Hasan Parvez on 19 Feb 2017
Edited: Walter Roberson on 19 Feb 2017
my matrix a is 2701x1
c = mat2cell(a, 1, diff([find(a == 1), length(a)+1]));
Error in tril121 (line 5)

Sign in to comment.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!