Divide 1D Array into a 2D Array by finding a flag value
2 views (last 30 days)
Show older comments
Hello,
I have a LabVIEW code where I am accquiring timestamps for scan lines, but at the end of each scan line, I have labview add a flag number into the array so I know where each scan line ends. I am trying to write a Matlab code, where I divide this 1D array to a 2D array (each row is the timestamps of 1 scan lines).
e.g. 1D Array = [10 11 12 13 14 15 18 19 0 21 23 24 25 26 27 28 29 0 31 34 35 36 36 38 39 40 0] here 0 is the flag. I want this to become a 2D array that is 2D Array = [10 11 12 13 14 15 18 19; 21 23 24 25 26 27 28 29; 31 34 35 36 36 38 39 40].
Best,
0 Comments
Answers (1)
KSSV
on 22 Nov 2017
A = [10 11 12 13 14 15 18 19 0 21 23 24 25 26 27 28 29 0 31 34 35 36 36 38 39 40 0] ;
B = [10 11 12 13 14 15 18 19; 21 23 24 25 26 27 28 29; 31 34 35 36 36 38 39 40] ;
flag = 0 ;
idx = find(A==flag) ;
L = unique(diff(idx)-1) ; % number of columns
% remove flags
A(A==0) = [] ;
% reshape to 2D array
iwant = reshape(A,[],L)
0 Comments
See Also
Categories
Find more on Matrices and Arrays 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!