How to convert for loop statement to matrix operation?

Hi, I am very new to using Matlab. Due to the processing issue, I would like to convert for-loop statement to matrix calculation to accelerate processing time.
For example,
[u v] = size(input_img);
for i=1:u
for j=1:v
if (input_img(i,j) == 0)
temp(i,j)=0;
end
end
end
Thank you.

 채택된 답변

James Tursa
James Tursa 2015년 8월 27일
편집: James Tursa 2015년 8월 27일
Assuming the matrix sizes are compatible, using logical indexing:
temp( input_img == 0 ) = 0;

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

제품

질문:

2015년 8월 27일

댓글:

2015년 8월 27일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by