While loop to get a specific section of data

15 次查看(过去 30 天)
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