Manahil
Manahil

Reputation: 265

For looping in MATLAB

Write the MATLAB code for drawing the following figure.

enter image description here

My attempt :

figure
axis equal 
axis([0 100 0 100])
for i = 10:10:90
    rectangle('position',[i/2,i,____,5],'curvature',[0 0],'facecolor','r')
end

I do not understand what to fill in the blank above. I know the values that should go are backward elements of i ,i.e. [90 80 70 60 50 40 30 20 10] but how to write it ? Please help.

Upvotes: 0

Views: 79

Answers (2)

Rash
Rash

Reputation: 4336

figure
axis equal 
axis([0 100 0 100])
for i = 10:10:90
    rectangle('position',[i/2,i,100-i,5],'curvature',[0 0],'facecolor','r')
end
grid on

Upvotes: 2

bteres
bteres

Reputation: 639

This has nothing to do with the for loop. It is rather a question of logic and algorithm design.

In this particular case you could use something like 100 - i. Alternatively, for a more general approach, you could set another counter that changes within the loop on every iteration.

Hope that helps and makes sense.

Upvotes: 2

Related Questions