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

 Risposta accettata

Jan
Jan il 24 Mar 2021
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 Commenti

themh sra
themh sra il 24 Mar 2021
ı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) = '#'
themh sra
themh sra il 24 Mar 2021
this code doesnt work for an empty square
Jan
Jan il 24 Mar 2021
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 .

Accedi per commentare.

Più risposte (0)

Categorie

Richiesto:

il 24 Mar 2021

Commentato:

Jan
il 24 Mar 2021

Community Treasure Hunt

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

Start Hunting!

Translated by