Q:

Write a function buildstr that will receive a character and a positive integer n. It will create and return a cell array with strings of increasing lengths, from 1 to the integer n

0

Write a function buildstr that will receive a character and a positive 

integer n. It will create and return a cell array with strings of 

increasing lengths, from 1 to the integer n. It will build the strings with

successive characters in the ASCII encoding.

>> buildstr('a',4)

ans = 

 'a' 'ab' 'abc' 'abcd'

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

buildstr.m

function outcell = buildstr(inchar, posint)

% Creates a cell array with strings of increasing

% lengths, from 1:n, starting with inchar

% Format of call: buildstr(input char, n)

% Returns cell array with n strings

outcell =cell(1,posint);

inchar = char(inchar-1);

strin = '';

for i = 1:posint

 strin = strcat(strin, char(inchar+i));

 outcell{i} = strin;

end

end

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now