Using for loop in matlab

2 次查看(过去 30 天)
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