I am creating a task in psychtoolbox and I need a grating for that. I made the grating and it is working well, but now I just want to cut some pieces out of it by setting those matrix elements to zero (currently I am using a mask instead, but I want to cut out pieces in the source, the grating itself).
To cut out the pieces I want, I need the indexes of the grating matrix (called A), so I figured I use ind2sub. This is however not working:
[I,J] = ind2sub(size(A),A);
'I' gives the same as 'A' and 'J' gives ones(size(A))
Example
Here is an example of what I'd like to do:
% A is a 3x3 matrix
% if I use "[I,J] = ind2sub(size(A),A);" I get the problem as described before:
% I = A and J = ones(3,3)
% When I use "[I,J] = ind2sub(size(A),[1:numel(A)]);" as suggested, I do get the
% following (which is a vector but can be reshaped into a 3x3 matrix):
I = [1 1 1 2 2 2 3 3 3]
J = [1 2 3 1 2 3 1 2 3]
I = reshape(I,[3,3]);
J = reshape(J,[3,3]);
K = I + J; % = [2 3 4; 3 4 5; 4 5 6]
for i=1:length(A)
for j=1:length(A)
if K(i,j)>*some threshold*
A(I(i),J(i))=0
end
end
end