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 日

0 投票

Assuming the matrix sizes are compatible, using logical indexing:
temp( input_img == 0 ) = 0;

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeLoops 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