Isolating and running a piece of code separately from the rest

조회 수: 1 (최근 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 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