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,

回答(1 个)

KSSV
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)

类别

Help CenterFile Exchange 中查找有关 LabVIEW 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by