Borrar filtros
Borrar filtros

Im lost sum1 help me with the code, im new to this Matlab programming

1 visualización (últimos 30 días)
Write a script that requests two positive integers greater than 3 (with error checking). The
numbers represent the x- and y-dimensions of a rectangle. Your program should then display a
rectangle of asterisks (*) with the specified dimensions. The rectangle with dimensions x = 5
and y = 4 would be displayed as :
*****
* *
* *
*****

Respuestas (1)

sixwwwwww
sixwwwwww el 3 de Dic. de 2013
Dear Merapelo, you can do it like this:
width = input('Enter width of rectangle (value should be positive and greater than 3): ');
if ~isnumeric(width)
error('Value for width is not a valid number')
elseif width < 4
error('Width is less than 3')
end
height = input('Enter height of rectangle (value should be positive and greater than 3): ');
if ~isnumeric(height)
error('Value for height is not a valid number')
elseif height < 4
error('Height is less than 3')
end
NumberOfAsteriksInEachDirection = 100;
x = [zeros(1, NumberOfAsteriksInEachDirection), linspace(0, width, NumberOfAsteriksInEachDirection), linspace(0, width, NumberOfAsteriksInEachDirection),...
ones(1, NumberOfAsteriksInEachDirection) * width];
y = [linspace(0, height, NumberOfAsteriksInEachDirection), zeros(1, NumberOfAsteriksInEachDirection), ones(1, NumberOfAsteriksInEachDirection) * height,...
linspace(0, height, NumberOfAsteriksInEachDirection)];
plot(x, y, '*'), xlim([-1 width+1]), ylim([-1 height+1])
I hope it helps. Good luck!

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by