Clear Filters
Clear Filters

how to divide a rectangle into 5 equal parts???

3 views (last 30 days)
arjun ramanujam
arjun ramanujam on 14 Jun 2015
Edited: Jan on 18 Jun 2015
i have defined a rectangle using this command
rectangle('Position',[800,900,500,1000]);
  1. How can i divide the rectangle into 5 equal parts horizontally
  2. Please help me sort this out thank you in advance

Answers (2)

Azzi Abdelmalek
Azzi Abdelmalek on 14 Jun 2015
Edited: Azzi Abdelmalek on 14 Jun 2015
n=5 % number of parts
h=rectangle('Position',[800,900,500,1000]);
pos=get(h,'position')
a=pos(3)/n
for k=1:n
hold on
new_pos=k*a
rectangle('Position',[pos(1:2) new_pos pos(4)]);
end
hold off
  4 Comments
arjun ramanujam
arjun ramanujam on 14 Jun 2015
Edited: arjun ramanujam on 14 Jun 2015
@jan simon i am learning matlab and i did not expect such a comment when learning you also might have had doubts what if i told you this that time ,everybody has doubts and this is a common forum and i am doing my mtech project if i could i would put my whole mtech project here as a doubt which my conscience would not permit and for the kind information this is a smallest part of my project of which only matlab related doubts are being put here of which the major part will be solved by me and not put here anyways @Azzi thank you for your answer
Jan
Jan on 14 Jun 2015
Edited: Jan on 18 Jun 2015
@Arjun: Your questions are welcome in this forum without any doubts. Of course this forum is based on questions.
But there are different kinds of answers: One type solves the problem as fast as possible, the other tries to assist you to solve the problem by your own. The later has the advantage, that you learn to solve other problems by your own in the future.
The readers can assume that you did try to solve your question by your own already. And in the majority of cases these trials are very good and match the exact question quite well. Only some typos or misunderstandings cause errors. Then posting a completely new answer will not be as useful as asking you to post, what you have tried so far and help you to fix the error.
Therefore a good question contains the required details and usually the relevant part of the code which has been created so far. See http://www.mathworks.com/matlabcentral/answers/6200-tutorial-how-to-ask-a-question-on-answers-and-get-a-fast-answer.
Especially for homework questions posting complete solutions is a serious problem, because some students copy the solutions and this is cheating. I do not think, that you want to cheat. I'm convinced that your question is serious and that Azzi is eager to solve your problem. But some other users try to misuse the forum as cheap solver and do not care about showing any own effort. And I think you could learn more, if you are assisted to solve the problem by your own. See http://www.mathworks.com/matlabcentral/answers/8626-how-do-i-get-help-on-homework-questions-on-matlab-answers .
Please accept Azzis answer if it solves your problem.
@Azzi: Okay. Thanks for your reply. I will stop to ask you repeatedly.

Sign in to comment.


Jan
Jan on 14 Jun 2015
Edited: Jan on 14 Jun 2015
This creates 5 rectangles with the same dimensions:
rectangle('Position', [ 800,900,100,1000])
rectangle('Position', [ 900,900,100,1000])
rectangle('Position', [1000,900,100,1000])
rectangle('Position', [1100,900,100,1000])
rectangle('Position', [1200,900,100,1000])

Community Treasure Hunt

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

Start Hunting!