Basic matlab help please

beer

Lifer
Jun 27, 2000
11,169
1
0
<--- really really hates matlab now

if img is a 512x512 matrix, and I want any element above 128 to go to 255 and anything below to go to 0, then why doesn't

if (img > 128)
img = 255;
else img = 0;
end;

work? Isn't the whole point of these vectorized operations to allow you to specify matricies and implicitly loop through them? My directions specifically say you cannot use any looping mechanisms at all.