MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Sean
on 7 May 2013

Assume that R is a positive integer and that f and b are single characters. If b is not given, use '.' . If f is not given, use '#'.

Ex

>>getatriangle(4,'@','-')

ans =

---@---

--@@@--

-@@@@@-

@@@@@@@

>> getatriangle(5)

ans =

....#....

...###...

..#####..

.#######.

#########

*No products are associated with this question.*

Answer by Iman Ansari
on 9 May 2013

Hi.

R = 20; f = '@'; b = '-';

max_num=2*R-1; fprintf('\n'); for i=1:R S1=repmat(b,[1 R-i]); S2=repmat(f,[1 2*i-1]); S=[S1 S2 S1]; fprintf('%s\n',S); end

## 2 Comments

## Matt Kindig

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/74971#comment_147870

Your output looks good. What is your question?

## Sean

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/74971#comment_147872

how to write the function haha. so far i have:

function t = getatriangle(R,f,b)

if nargin == 1;

f = '#';

b = '.';

end