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

1 vue (au cours des 30 derniers jours)
Merapelo CHamme
Merapelo CHamme le 3 Déc 2013
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 :
*****
* *
* *
*****

Réponses (1)

sixwwwwww
sixwwwwww le 3 Déc 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!

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by