Using for loop in matlab

조회 수: 2 (최근 30일)
Aftab Ahmed Khan
Aftab Ahmed Khan 2015년 2월 2일
편집: Matt J 2015년 2월 2일
Hi everyone, I am assigning these values not in a very efficient way, can you suggest me how can i do it more efficiently? Thank you so much.
%Zone 1
absx(1,81)=0;
absy(1,81)=0;
absx(1,82)=0;
absy(1,82)=0;
absx(1,83)=450;
absy(1,83)=0;
absx(1,84)=450;
absy(1,84)=0;
absx(1,85)=450;
absy(1,85)=450;
absx(1,86)=450;
absy(1,86)=450;
absx(1,87)=0;
absy(1,87)=450;
absx(1,88)=0;
absy(1,88)=450;
%Zone 2
absx(1,89)=0;
absy(1,89)=900;
absx(1,90)=0;
absy(1,90)=900;
absx(1,91)=450;
absy(1,91)=900;
absx(1,92)=450;
absy(1,92)=900;
absx(1,93)=450;
absy(1,93)=1350;
absx(1,94)=450;
absy(1,94)=1350;
absx(1,95)=0;
absy(1,95)=1350;
absx(1,96)=0;
absy(1,96)=1350;
%Zone 3
absx(1,97)=900;
absy(1,97)=0;
absx(1,98)=900;
absy(1,98)=0;
absx(1,99)=900+450;
absy(1,99)=0;
absx(1,100)=900+450;
absy(1,100)=0;
absx(1,101)=900+450;
absy(1,101)=450;
absx(1,102)=900+450;
absy(1,102)=450;
absx(1,103)=900;
absy(1,103)=450;
absx(1,104)=900;
absy(1,104)=450;
%Zone 4
absx(1,105)=900;
absy(1,105)=900;
absx(1,106)=900;
absy(1,106)=900;
absx(1,107)=900+450;
absy(1,107)=900;
absx(1,108)=900+450;
absy(1,108)=900;
absx(1,109)=900+450;
absy(1,109)=900+450;
absx(1,110)=900+450;
absy(1,110)=900+450;
absx(1,111)=900;
absy(1,111)=1350;
absx(1,112)=900;
absy(1,112)=1350;
  댓글 수: 2
Andreas Goser
Andreas Goser 2015년 2월 2일
Why do you think it is not efficient?
Aftab Ahmed Khan
Aftab Ahmed Khan 2015년 2월 2일
Well, its like 60 lines of code for doing a simple task. I am sure it can be done more efficently in a for loop.

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

채택된 답변

Matt J
Matt J 2015년 2월 2일
편집: Matt J 2015년 2월 2일
You would do things like the following
absx=zeros(1,112);
absy=zeros(1,112);
%Zone 1
absx(83:86)=450;
absy(85:88)=450
and similarly for the other Zones.

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by