Cut section of data from one vector with start and end elements of section from second vector
조회 수: 6 (최근 30일)
이전 댓글 표시
Hi MATLAB community!
I have a approx. 300.000 x 3 double matrix containing physiolog. data. Column 1 is the raw data (which I ultimately need), column 2 are timestamps for each single value from column 1 (so column 1 and to ahve the same length). And column 3 has also timestamps, but for each trigger from the MRT - this means, there are only around 900 time values there.
In order for me to get the correct section of column 1, I need to somehow relate these columns to each other. There are also two conditions, that's why I first located the conditions in column 3 and got the index for each occurrence of each condition. Then I aimed to get the timestamp for each occurrecne of each condition (so that I can then relate it to column 2). But the thing is that I don't just need a certain timepoint, I need a whole section. That's why I subtracted approx. 7s from each time stamp. The time range I need is therefore the timestamp (i.e., timepoint) extracted from column 3 minus 7 s.
My problem is now that I'm having troubles getting this time range from column 2. So I'd need to somehow compare elements from column 3 and column 2. And if there's a match with, say element a, elements from a until the element a-7 s should be added into a list. Since my column 1 and 2 are huge I can't just iterate in a for loop over both columns. Ideally, I'd then get the index of the range of column 2 and, in a last step, extract the correct raw data values for the correct time window and condition.
Can anyone help?
Thanks a lot in advance!
% get index of press per condition for column 3
idx_local = [];
idx_global = [];
for i = 1:length(log.key.idDown) % log.key.idDown tells me which condition happens when
if log.key.idDown(i) == 11
idx_local(i) = i;
elseif log.key.idDown(i) == 12
idx_global(i) = i;
end
end
idx_local = idx_local(idx_local > 0)';
idx_global = idx_global(idx_global > 0)';
%% get timestamp of press per condition (still column 3)
a = resp_PT02(:,3); % times of triggers
raw_stamp_local = [];
raw_stamp_global = [];
for j = 1:length(a)
for i = 1:length(idx_local)
if idx_local(i) == j
raw_stamp_local(j) = a(j)
end
end
end
raw_stamp_local = raw_stamp_local(raw_stamp_local > 0)';
for j = 1:length(a)
for i = 1:length(idx_global)
if idx_global(i) == j
raw_stamp_global(j) = a(j)
end
end
end
raw_stamp_global = raw_stamp_global(raw_stamp_global > 0)';
%% get correct time window (raw_stamp_local/global contain two colums: 1) onset of condition, 2) offset); for both condtions respectively.
raw_stamp_local_full = raw_stamp_local - 7.04; % subtract 8 TRs
raw_stamp_local(:,2) = raw_stamp_local_full;
raw_stamp_global_full = raw_stamp_global - 7.04; % subtract 8 TRs
raw_stamp_global(:,2) = raw_stamp_global_full;
댓글 수: 2
Star Strider
2021년 12월 13일
It would help to have the file (or a representative sample), as well as an example of the desired result, specifically with respect to the third column.
.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Low-Level File I/O에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!