Isolating and running a piece of code separately from the rest

1 visualización (últimos 30 días)
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 comentario
Guillaume
Guillaume el 21 de Jul. de 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?).

Iniciar sesión para comentar.

Respuesta aceptada

Guillaume
Guillaume el 21 de Jul. de 2019
Editada: Guillaume el 21 de Jul. de 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 comentarios
Nikolaos Zafirakis
Nikolaos Zafirakis el 21 de Jul. de 2019
Editada: Guillaume el 21 de Jul. de 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 el 21 de Jul. de 2019
FIxed, I made a stupid edit after pasting the code.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Introduction to Installation and Licensing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by