MATLAB: How to write a program to draw a triangle of stars in MATLAB

homework

I have a exam and don't know how to write a program to draw a triangle of stars, for example :
*
**
***
****
*****
And also flip upside down, for example :
*
**
***
****
*****
And also in the form of isosceles triangle, for example :
*
***
*****
*******
And also in the form of a specific, for example :
*
***
*****
*******
*****
***
*
Please help me!

Best Answer

Hint:
string = ' '; % 5 spaces.
index1 = 2;
index2 = 4;
string(index1:index2) = '*';
fprintf('%s\n', string);
You need to figure out what index1 and index2 are for the various lines you want to print out.
Related Question