필터 지우기
필터 지우기

compressing a code, help me

조회 수: 2 (최근 30일)
Cauli Vilela Ferreira
Cauli Vilela Ferreira 2020년 7월 2일
답변: Image Analyst 2020년 7월 2일
Any one knows how to compress this code as much as possible?
for VetorN = fix((20*sqrt(2).^(0:5)))
[row,col] = size(VetorN);
i = (1: col);
discSt.N = VetorN(i);
VN = VetorN;
CD0 = VetorN *3;
if VetorN == 20
CD01 = CD0;
elseif VetorN == 28
CD02 = CD0;
elseif VetorN == 40
CD03 = CD0;
elseif VetorN == 56
CD04 = CD0;
else
CD05 = CD0;
end
pause()
end
MCD0 = [CD01 CD02 CD03 CD04 CD05]
  댓글 수: 2
madhan ravi
madhan ravi 2020년 7월 2일
Why do you use pause()?
Cauli Vilela Ferreira
Cauli Vilela Ferreira 2020년 7월 2일
because generate a plot after each pause

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

채택된 답변

madhan ravi
madhan ravi 2020년 7월 2일
VetorN = fix( (20 * sqrt(2) .^ (0 : 5) ) )
MD0 = VetorN * 3;
MD0(end - 1) = [ ]
  댓글 수: 4
Cauli Vilela Ferreira
Cauli Vilela Ferreira 2020년 7월 2일
How cant i add VetorN(1,5), i forgot to put in the code
for VetorN = fix((20*sqrt(2).^(0:5)))
[row,col] = size(VetorN);
i = (1: col);
discSt.N = VetorN(i);
VN = VetorN;
CD0 = VetorN *3;
if VetorN == 20
CD01 = CD0;
elseif VetorN == 28
CD02 = CD0;
elseif VetorN == 40
CD03 = CD0;
elseif VetorN == 56
CD04 = CD0;
elseif VetorN== 80
CD05 = CD0;
else
CD06 = CD0;
end
pause()
end
MCD0 = [CD01 CD02 CD03 CD04 CD05 CD06]
madhan ravi
madhan ravi 2020년 7월 2일
So remove the last line in my code ;)

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

추가 답변 (1개)

Image Analyst
Image Analyst 2020년 7월 2일
Not sure why it needs to be compressed as much as possible, but this will compress it as much as possible while giving the very same output:
MCD0=[60,84,120,168,339]
This assumes that after that you no longer need the component variables CD01, CD02, CD03, CD04, CD05, and CD06. If you still need those variables for some reason, then of course you'll need to compute them.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by