MATLAB: Can I use boolean of a variable on a column of another variable

booleancolumn

Hi,
I'm new here to mathworks so I apologise if I don't give all the relevant information right away.
Say I have the variables target(range 1:4) and response(matrix with 10000×16 values)
I want to iterate through each response column and extract the values linked to a specific target and add them to a different vector (Like response(target==2) but for each column seperately)
Right now I have something like:
Resp=[]
For i=1:16
Resp=[Resp, response(:,i)(target==2)]
End
This doesn't work. How can i rewrite it?

Best Answer

Resp=response(target==2,:);