Isolating and running a piece of code separately from the rest

1 vue (au cours des 30 derniers jours)
Nikolaos Zafirakis
Nikolaos Zafirakis le 21 Juil 2019
Commenté : Guillaume le 21 Juil 2019
So, I have a piece of simple code below. I want to isolate all the different groups relative to the measurements thus A relative to B such that I can run P in separate intervals because the code tends to drift after a certain amount of measurements.
A = (:,1:3) % measurements 1000 rows by 3 columns
B = (:,1) % Data groups 1000 rows showing were the groups start and finish
[ D, E ] = find( B == 0 ); % D when a group starts
F = D - 1; % F when a group finishes
P = unwrap(A)
  1 commentaire
Guillaume
Guillaume le 21 Juil 2019
I want to isolate all the different groups
You haven't told us how a group is indicated. Possibly, from the code in the (invalid) code, a new group starts when B is 0 (so elements of a group are contiguous?).

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 21 Juil 2019
Modifié(e) : Guillaume le 21 Juil 2019
A complete guess, if you want to split A into groups that start when B is 0 and apply unwrap to each group:
group = cumsum(B == 0) + double(B(1) ~= 0); %add one if B(1) is not zero. group must be positive integer
P = splitapply(@(m) {unwrap(m)}, A, group);
P will be a Nx1 cell array where P{i} is the result of applying unwrap to the ith group of A.
  2 commentaires
Nikolaos Zafirakis
Nikolaos Zafirakis le 21 Juil 2019
Modifié(e) : Guillaume le 21 Juil 2019
Yes I want to start a group when B = 0.
[ D, E ] = find( B == 0 ); % D when a group starts
F = D - 1; % F when a group finishes
Using these to commands I basically have 601 points where a 0 occurs and 601 points from F where the end of a batch occurs the batches or groups are pretty random. The code you provided errors
Error using splitapply (line 61)
Group numbers must be a vector of positive integers, and cannot be a sparse vector.
I think it is because the "group brings up all zeros".
Guillaume
Guillaume le 21 Juil 2019
FIxed, I made a stupid edit after pasting the code.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Introduction to Installation and Licensing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by