How to extract data from two separate tabs
이전 댓글 표시
I have heart rate and time in two columns. I am going to filter heart rates above 95 bpm. However, in another two columns I have certain "events" that occurred throughout the recording and the times the events occurred. The time of the events don't necessarily match up with the time of the heart rates I want to extract. Tips on creating a script to filter out the heart rates above 95 along with the event that precedes the high heart rate??
답변 (1개)
Matt Gaidica
2021년 1월 22일
0 개 추천
The easiest way to think about this would be using a simple series find statements and the returned indexes to do time comparisons, as well as pull event type.
Post a sample of your actual data, I can imagine some caveats and best practices depending on how it's formatted.
댓글 수: 4
Sam
2021년 1월 22일
Matt Gaidica
2021년 1월 22일
편집: Matt Gaidica
2021년 1월 22일
I think either attaching the spreadsheet or getting it into MATLAB is a good start—you can use readtable. I'm happy to illustrate some code if you attach your spreadsheet (I work in physiology as well!).
Matt Gaidica
2021년 1월 22일
편집: Matt Gaidica
2021년 1월 22일
Sure thing. Try this:
hrIds = find(Data{:,'Heart Rate'} > 95);
hrTimes = Data{hrIds,'Heart Rate Times'};
eventCodes = NaN(1,numel(hrTimes));
for ii = 1:numel(hrTimes)
precTimeId = find(Data{:,'Event Times'} < hrTimes(ii),1,'last');
if ~isempty(precTimeId)
eventCodes(ii) = Data{precTimeId,'Event Code'};
end
end
You have some heart rate times that come before the first event, so those are left as NaN.
카테고리
도움말 센터 및 File Exchange에서 Analysis of Variance and Covariance에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!