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

 Respuesta aceptada

Jan
Jan el 24 de Mzo. de 2021

0 votos

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 comentarios

themh sra
themh sra el 24 de Mzo. de 2021
ıt works, thank you so much! But I couldnt find how to print an empty square
Jan
Jan el 24 de Mzo. de 2021
See this:
S = repmat('*', n, n);
S(2:3, 3:4) = '#'
themh sra
themh sra el 24 de Mzo. de 2021
this code doesnt work for an empty square
Jan
Jan el 24 de Mzo. de 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 .

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre MATLAB Mobile Fundamentals en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 24 de Mzo. de 2021

Comentada:

Jan
el 24 de Mzo. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by