Effacer les filtres
Effacer les filtres

Divide 1D Array into a 2D Array by finding a flag value

1 vue (au cours des 30 derniers jours)
Hussam Ibrahim
Hussam Ibrahim le 22 Nov 2017
Réponse apportée : KSSV le 22 Nov 2017
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,

Réponses (1)

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

Catégories

En savoir plus sur LabVIEW dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by