Simplify this code snippet

조회 수: 2 (최근 30일)
hmhuang
hmhuang 2021년 11월 25일
댓글: Image Analyst 2021년 11월 25일
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

답변 (1개)

Walter Roberson
Walter Roberson 2021년 11월 25일
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
hmhuang
hmhuang 2021년 11월 25일
@Walter Roberson Can you show how to do it in one assignment?
Image Analyst
Image Analyst 2021년 11월 25일
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).

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Energy Production에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by