using 'find' in matrix

조회 수: 14 (최근 30일)
Dylan
Dylan 2013년 5월 22일
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
Walter Roberson
Walter Roberson 2013년 5월 22일
The code has no variable named "v" so we cannot tell.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
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
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 CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by