how can I write a rectangle and a square which sizes are users chooses numbers? does it must be with matrix or whatever else?
what ı mean ıs down there

 采纳的回答

S = repmat('*', n, n) % A square
% Or:
S = '';
S(1:n, 1:n) = '*';
For a square, you have to set the elements (2:n-1, 2:n-1) to the space afterwards.

4 个评论

ıt works, thank you so much! But I couldnt find how to print an empty square
See this:
S = repmat('*', n, n);
S(2:3, 3:4) = '#'
this code doesnt work for an empty square
Which code does not run for what input? What exactly is "an empty square"? n=0?
What does "doesn't work" mean? Please post the code you use and the error message you get.
I showed how to insert # characters as a rectangular shape. I assume, that you can replace '#' by ' ' and 2:3 by 2:n-1 .

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 MATLAB Mobile Fundamentals 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by