using 'find' in matrix
12 ビュー (過去 30 日間)
古いコメントを表示
There is a data called "EMG_data" That is a very large dataset. I want to find the location/index that goes over a threshold. This point where the value goes over the threshold value is called 'onset time'.
if true
indOn=4*ones(3,15);
Edata=5*ones(size(EMG_data(:,2:16)));
% Edata is the same size as the original or raw data.
% Range or duration of one trial
rg1=marker_2:marker_7;
for v1=1:15
for r1 = 1:length(EMG_data(rg1,v1+1))
if EMG_data(r1, v1+1) > Threshold(1,v1)
Edata(r1,v1)=1; % assign '1' for the values above the threshold
indOn(1,v1) = find(Edata(rg1,v1)==1,1); %Index for onset time
else
% if the value is not above threshold, then '0' is assigned
Edata(r1,v1) = 0;
end
end
if indOn(1,v1)==0
indOn(1,v1)= marker_7-marker_2+1;
end
end
end
I checked my work with more simple code (below). The below code works, so I based the above code on the simpler code. However, it doe snot work.
if true
a=[1 5 3 4 5; 1 7 8 9 0; 1 2 3 4 6; 1 6 5 4 3];
ind=zeros(1,5);
u=4*ones(4,5);
%Want to analyze each participant separately
for b=1:5
for r=1:length(a(:,b))
if a(r,b)<4
u(r,b)=1;
ind(1,b) = find(u(:,b)==1,1);
else
%If the participant did not do more than 4 push-ups during 4
%trials, then I want to assign '5'.
u(r,b)=0;
end
end
if ind(1,b)==0
ind(1,b)=75;
end
end
end
I am getting 'Subscripted assignment dimension mismatch' error for 'indOn(1,v1) = find(Edata(rg1,v1)==1,1);' line.
When I checked, it seems like the first IF statement of the top code is not working properly. If the code finds a value above the threshold, then I want the code to assign '1'. Otherwise, '0' will be assigned. However, '1's or '0's are not being assigned.
I cannot see why this would no work. What could be done to fix this?
1 件のコメント
回答 (1 件)
Walter Roberson
2013 年 5 月 22 日
In your code a(r,b) is a scalar variable, so a(r,b)>4 is going to be a scalar and so the result of the find() can only be 0 or 1.
What you should be looking at is find(a(:,b)>4,1)
1 件のコメント
Image Analyst
2013 年 5 月 24 日
I'm not even sure the find() is needed. Often when people say they want to know where an array exceeds a threshold they can get by just fine with the logical indexes and don't really need to know actual row and column numbers.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!