When I search for a floating point (decimal) number within a matrix in MATLAB, it does not find it even though it should be there. Specifically, I need to find a number, say yy = 0.9600
, in the matrices X
and Y
but MATLAB does not find them. How to go around this problem?
A = reshape(1:10000,100,100).'; %'
p = size(A,1);
B = zeros(p,p);
[X,Y] = meshgrid(0:p-1,0:p-1); X = X ./ p; Y = Y ./ p;
X = round(X*10000) / 10000;
Y = round(Y*10000) / 10000;
Y = flipud(Y);
for i=1:p,
for j=1:p,
x = X(j,i);
y = Y(j,i);
xx = mod((x+y),1);
yy = mod((x+2*y),1);
[r, c] = find(X==xx); %// NOT FOUND
[rr, cc] = find(Y==yy); %// "
a = A(j,i);
B(rr(1),c(1)) = a;
end
end