How to use "zeros" to replace for loop?

Hello,
I would like to use zeros to replace the for loop, I had try it before but have some errors. How to use zeros to replace for loop?
for a = 300 :2: 303;
for b = 353 :2: 381;
for c = 301 :2: 303;
for d = 354 :2: 381;
frame1(a,b,:) = [0,0,0];
frame1(c,d,:) = [0,0,0];
end
end
end
end
Here is the loop, Thanks.

2 件のコメント

Image Analyst
Image Analyst 2012 年 4 月 28 日
You don't have to put semicolons at the end of the "for" lines - it doesn't have any effect.
Jan
Jan 2012 年 4 月 28 日
"frame1(c,d,:) = 0;" is sufficient and faster than "frame1(c,d,:) = [0,0,0];". But of course Walter's solution is ways faster.

サインインしてコメントする。

回答 (2 件)

Walter Roberson
Walter Roberson 2012 年 4 月 28 日

1 投票

frame1(300:303, 353:381,:) = 0;
Wayne King
Wayne King 2012 年 4 月 28 日

0 投票

frame1 = zeros(303,381,3);

3 件のコメント

Peony Lai
Peony Lai 2012 年 4 月 28 日
Thankyou for your answer, but the for loop is a range of coordinate, it not just 1 coordinate, and I need to make the pixel which is mentioned in the for loop to be black color, I have tried you method but didn't work, thanks.
Wayne King
Wayne King 2012 年 4 月 28 日
Then I'm not sure what you're asking because my line gives the exact result of your for loop
Walter Roberson
Walter Roberson 2012 年 4 月 28 日
Wayne, assume that frame1 is a previously-initialized array.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

質問済み:

2012 年 4 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by