Azzera filtri
Azzera filtri

Ask for partitioning a matrix

1 visualizzazione (ultimi 30 giorni)
Bundit Buddhahai
Bundit Buddhahai il 19 Apr 2014
Commentato: Bundit Buddhahai il 28 Apr 2014
Hi, I have an input matrix of 2 columns data, the first column is time index data and the second one is data which represent the status of that number (which says, if the number is positive, the number label is ‘On’ whereas when the number is negative, the number label is ‘Off’). The process of ‘On’ (positive)/ ’Off’ (negative) for each number is time sequential data (data in the 2nd column) in which the frequency for ‘On’/ ‘Off’ state for each number is arbitrary. The ‘Off’ state for each number is the one which is the closest in time index to positive value of the same number.
Thank you. Bundit
I would like to make partitions of the input matrix to get positive/negative value that represent ‘On’/’Off’ state of each existing number in the matrix. The example is shown in the attached image

Risposta accettata

Andrei Bobrov
Andrei Bobrov il 22 Apr 2014
Modificato: Andrei Bobrov il 24 Apr 2014
[~,~,c] = unique(abs(X(:,2)));
out = accumarray(c,(1:numel(c))',[],@(x){X(x,:)});
add
[a,~,c] = unique(abs(X(:,2)));
out = [a, accumarray(c,-sign(X(:,2)).*X(:,1))];
  5 Commenti
Andrei Bobrov
Andrei Bobrov il 25 Apr 2014
[a,~,c] = unique(abs(X(:,2)));
out = [a, accumarray(c,-sign(X(:,2)).*X(:,1))];
Bundit Buddhahai
Bundit Buddhahai il 28 Apr 2014
Many thanks Bobrov, your method is concise but very excellent. Great!

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Data Types in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by