Simplify this code snippet
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Can someone advise me how to simplify this 10 lines of code into a beautiful and elegamt one single line of code, if possible?
meshx = 100;
meshy = 50;
passiveVoid = ones(meshy, meshx);
for i = 1:meshx
for j = 1:meshy
if (sqrt((j-meshy/2)^2+(i-meshx/3)^2) < meshy/3)
passiveVoid(j,i) = 0;
end
end
end
0 Kommentare
Antworten (1)
Walter Roberson
am 25 Nov. 2021
No. It can be done in one assignment, but it will not be beautiful or elegant. You need three assignments to make it reasonable.
2 Kommentare
Image Analyst
am 25 Nov. 2021
Why? The code will be horrible. It will be cryptic and not at all easy for anyone to understand. It won't be maintainable code. No one but you will be able to understand it. It's better to have a few understandable steps rather than one horrendously complicated step (which actually would have several steps internal to it).
Siehe auch
Kategorien
Mehr zu Logical 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!