Isolating and running a piece of code separately from the rest

2 ビュー (過去 30 日間)
Nikolaos Zafirakis
Nikolaos Zafirakis 2019 年 7 月 21 日
コメント済み: Guillaume 2019 年 7 月 21 日
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".
Guillaume
Guillaume 2019 年 7 月 21 日
FIxed, I made a stupid edit after pasting the code.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeIntroduction 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