Divide 1D Array into a 2D Array by finding a flag value
1 回表示 (過去 30 日間)
古いコメントを表示
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 件のコメント
回答 (1 件)
KSSV
2017 年 11 月 22 日
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 件のコメント
参考
カテゴリ
Help Center および File Exchange で Matrices and Arrays についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!