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 ?
1 view (last 30 days)
Show older comments
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
4 Comments
Accepted Answer
KSSV
on 25 Jul 2018
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
3 Comments
More Answers (0)
See Also
Categories
Find more on Lighting, Transparency, and Shading in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!