필터 지우기
필터 지우기

I would like to know if my function is correct

조회 수: 1 (최근 30일)
Alex castilla
Alex castilla 2018년 3월 8일
답변: njj1 2018년 3월 8일
Hello,
I would like to know if this function is right. I have a dataset with 4 columns , the first and second column are the x,y coordinates for the participants locomotion, the third and fourth columns are the X,Y coordinates for the targets (total targets =9, ). I would like to know if the function will tell me whether the participant reached a target or several targets during de locomotion. The aim is to create a column with the result (x>=X && x<=X+w )&&( y>=Y && y<=Y+h). Thanks
w=0.2;%width
h= 0.2;% height
Reach_target=b'
data= [data Reach_target];
function b= proof(x,X,y,Y)
b=[];
for i= 1:length(x)
for ii= 1:length(X)
if x(i)>=X(ii) && x(i)<=X(ii)+w;
d= 1;
end
end
end
for e= 1:length(y)
for ee= 1:length(Y)
if y(e)>=Y(ee) && y(e)<=Y(ee)+h;
c=1;
end
end
end
b=d+c;
end

답변 (1개)

njj1
njj1 2018년 3월 8일
You actually need not go through the whole for loop to do this. First off, I assume the number of entries in x is equal to the number of entries in X (and the same for y and Y). You can simply use Boolean logic here. For an "and" statement, you multiply, and for an "or" statement, you add.
d1 = x>=X;
d2 = x<=X+w;
b1 = y>=Y;
b2 = y<=Y+h;
out = d1*d2*b1*b2;

카테고리

Help CenterFile Exchange에서 Explore and Edit Images with Image Viewer App에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by