Isolating and running a piece of code separately from the rest

2 次查看(过去 30 天)
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 个评论
Guillaume
Guillaume 2019-7-21
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?).

请先登录,再进行评论。

采纳的回答

Guillaume
Guillaume 2019-7-21
编辑:Guillaume 2019-7-21
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 个评论
Nikolaos Zafirakis
Nikolaos Zafirakis 2019-7-21
编辑:Guillaume 2019-7-21
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".

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by