While loop to get a specific section of data

조회 수: 14 (최근 30일)
Sydney Kehoe
Sydney Kehoe 2021년 6월 8일
댓글: Sydney Kehoe 2021년 6월 9일
resp = [];
ii = 1;
n = 720000;
go = 0;
while ii < length(acq2.data(:,4))
if acq2.data(ii,4) > 1 && go == 0
resp(ii) = acq2.data(ii,3);
go = 1;
else
ii = ii + 1;
end
jj = 1;
if go == 1 && jj < n
resp(ii) = acq2.data(ii,2);
jj = jj + 1;
end
if go == 1
ii = ii + 1;
end
end
So basically what I am trying to do here is use column 4 data (which ranges from 0.1 when it is resting and it jumps up to 5 when it is active) so I want to start moving data into the new array at the first instance ii when the data in column 4 jumps up to 5 (in this case when it is greater than 1). Since I only want this to happen once I made sure go at first equals 0 and when this condition is first met it then becomes g=1 so that it does not repeat that aspect of the code. So ideally this will create a new column of data in the new array resp where it starts at some point ii where the data in column 4 first is greater than 1 and then it ends some 720000 points later.
  댓글 수: 1
Sydney Kehoe
Sydney Kehoe 2021년 6월 8일
For example if ii = 5779 where acq2.data(:,4) at that point is 5 the new array resp =[] would start being filled at row 5779 continuing through ii = 725779 (since n = 720000). I'm thing the go scenario will ensure that the acq2.data>1 only has to be met once. As of right now this code seems to start inputting data into a new array when acq2.data>1 but then altnerates between listing values and zeroes from there on out.

댓글을 달려면 로그인하십시오.

채택된 답변

dpb
dpb 2021년 6월 9일
편집: dpb 2021년 6월 9일
Far easier if you would attach a (small) sample of the dataset, but the general idea would be
thresholdUp=1; % set the rising threshold level
thresholdDn=0.1; % and the falling
i1=find(Data(:,4)>=thresholdUp,1); % the first above threshold
i2=find(Data(i1:end,4)<thresholdDn,1)+i1; % the first value below drop threshold after start
newData=Data(i1:i2,:); % save the data between events
  댓글 수: 1
Sydney Kehoe
Sydney Kehoe 2021년 6월 9일
Thanks for your help! It ended up being something closer to what I have but thank you for your time all the same!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by