MATLAB: I have a matrix BB = [-1 5 6;4 -3 2;5 6 -7]. How can i print the location(index) of the positive elelments using for loop and using while loop

for loophomeworkMATLABmatrixwhile loop

I have this matrix BB = [-1 5 6;4 -3 2;5 6 -7]. I want to know how can I display the location of the positive elements using for loop and using while loop

Best Answer

BB = [-1 5 6;4 -3 2;5 6 -7] ;
[nx,ny] = size(BB) ;
for i = 1:nx
for j = 1:ny
if BB(i,j)>0
fprintf('%d %d %f\n',i,j,BB(i,j))
end
end
end