Filter löschen
Filter löschen

code without for loop

1 Ansicht (letzte 30 Tage)
Sajid
Sajid am 5 Dez. 2012
Hi,
i have an index variable. Each row contains an x,y coordinate. i can loop through each x,y and set value. but i cannot achieve this without for loop. Can anyone tell me how to run this code without for loop?
for i=1:size(index,1)
mask(index(i,1),index(i,2)) = 255;
end
Thanks,
Sajid

Antworten (1)

Matt Fig
Matt Fig am 5 Dez. 2012
idx = sub2ind(size(mask),index(:,1),index(:,2));
mask(idx) = 255;

Kategorien

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

Community Treasure Hunt

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

Start Hunting!

Translated by