フィルターのクリア

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 Center および File ExchangeExplore 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