I would like to know if my function is correct
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
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
0 Commenti
Risposte (1)
njj1
il 8 Mar 2018
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;
0 Commenti
Vedere anche
Categorie
Scopri di più su Explore and Edit Images with Image Viewer App in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!