Indexing position at EMG onset
4 次查看(过去 30 天)
显示 更早的评论
I am trying to index position at EMG onset with below code but its not working
%find index where time = 0 (ROI starts)
time_0 = cellfun(@(time_2000Hz) find(time_2000Hz == 0), time_2000Hz, 'UniformOutput',false);
%position when ROI starts
for tr=1:ntr-1
position_0(:,tr) = pos{tr}(1:time_0{tr});
end
%% cell to martix for pos
maxRows = 1;
for xx = 1:length(pos)
if length(pos{xx}) > maxRows
maxRows = length(pos{xx});
end
end
Pos= nan(maxRows,length(pos)); %make NaN array
%loop through your cell array and paste data into NaN array
for yy = 1:length(pos)
Pos(1:length(pos{yy}),yy) = pos{yy};
end
%% shift position to start at 0 when ROI starts
for tr=1:ntr-1
b1(:,tr)= Pos(tr) - position_0(:,tr);
end
%% EMG activation threshold
%create vector of logicals flagging baseline window based on time column
baselineROI=cellfun(@(time_2000Hz) time_2000Hz>=-1000 & time_2000Hz<0, time_2000Hz, 'UniformOutput', false);
%create array with baseline window from EMG stretched column
for tr=1:ntr-1
ebaseline(:,tr) = Rec_filtered_data{tr}(baselineROI{tr});
end
%find mean baseline EMG
for tr=1:ntr-1
ebaseline_mean(:,tr) = mean(ebaseline(tr));
end
%calculate baseline EMG threshold value (mean baseline EMG + 2.5 SD)
STD=std(ebaseline);% STD
for tr=1:ntr-1
ethreshold(:,tr) = (ebaseline_mean(:,tr) + 2.5 * STD(:,tr));
end
%% Cell to matrix
%loop through to find the largest data set in your cell array
maxRows = 1;
for xx = 1:length(Movav_data)
if length(Movav_data{xx}) > maxRows
maxRows = length(Movav_data{xx});
end
end
Movav= nan(maxRows,length(Movav_data)); %make NaN array
%loop through your cell array and paste data into NaN array
for yy = 1:length(Movav_data)
Movav(1:length(Movav_data{yy}),yy) = Movav_data{yy};
end
%% EMG onset and Offset
for tr=1:10
activation(:,tr)= find(Movav(:,tr) >= ethreshold(:,tr),1,"First");
deactivation(:,tr)= find(Movav(:,tr) >= ethreshold(:,tr),1,"Last");
end
%time index where EMG moving average first increases and decreases over threshold
for tr=1:10
activation_time(:,tr) = time_2000Hz{tr}(activation(:,tr));
end
for tr=1:10
deactivation_time(:,tr)=time_2000Hz{tr}(deactivation(:,tr));
end
% EMG Burst duration
burst_time = deactivation_time - activation_time;
%find EMG activation index
for i=1:10
activation_time_index(i) = find(Rec_filtered_data{i} >= activation_time(:,tr),1,'first');
end
%%position where EMG first increases over threshold
for i=1:10
activation_position(i) = b1(activation_time_index(:,i),1);
end
The last two for loop are not working
Thanks
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!