Filter löschen
Filter löschen

How to use "zeros" to replace for loop?

4 Ansichten (letzte 30 Tage)
Peony Lai
Peony Lai am 28 Apr. 2012
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 Kommentare
Image Analyst
Image Analyst am 28 Apr. 2012
You don't have to put semicolons at the end of the "for" lines - it doesn't have any effect.
Jan
Jan am 28 Apr. 2012
"frame1(c,d,:) = 0;" is sufficient and faster than "frame1(c,d,:) = [0,0,0];". But of course Walter's solution is ways faster.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Walter Roberson
Walter Roberson am 28 Apr. 2012
frame1(300:303, 353:381,:) = 0;

Wayne King
Wayne King am 28 Apr. 2012
frame1 = zeros(303,381,3);
  3 Kommentare
Wayne King
Wayne King am 28 Apr. 2012
Then I'm not sure what you're asking because my line gives the exact result of your for loop
Walter Roberson
Walter Roberson am 28 Apr. 2012
Wayne, assume that frame1 is a previously-initialized array.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by