|
"Lin"
> Thanks for replying, I would like to apologise for the confusion, but this is not what i want. Let me give a more specific example. Say
> x = [0 11 12; 0 12 11; 0 12 12];
> for row=1:3 %nested for-loop
> for col=1:3
> if (x(row,col) == 11)
> disp('11 is found')
> end
> end
> end
> S{1} = sparse(cell2mat(T1));
> S{2} = sparse(cell2mat(T2));
> % Suppose to be nested-for loop as before.. However, I cant get the same results using the nested for-loop. Is there something else which can achieve what i need> Thanks.. Hope this is clear enough...
well, why did you not mention the nested for-loop before...
moreover, the proposed snippet does exactly what you want - did you bother to look at it?...
again,
clear s; % <- save old stuff!
s{1}=sparse([0,11,11;11,0,0;0,11,0]);
[sr,sc]=find(s{1}==11); % <- get row#/col#
% now, SR/SC contain the valid row/col numbers, which you
% extract in your nested loop in
% if (x(row,col) == 11)
% hence, if you really want to do things in a loop, use it as follows
for i=1:numel(sr)
disp(sprintf('11 found at row/col# %3d/%3d',sr(i),sc(i)));
end
%{
11 found at row/col# 2/ 1
11 found at row/col# 1/ 2
11 found at row/col# 3/ 2
11 found at row/col# 1/ 3
%}
us
|