Q:

Write a function “createUniqueName” that will create a series of unique names. When the function is called, a string is passed as an input argument. The function adds an integer to the end of the string,

0

Write a function “createUniqueName” that will create a series of 

unique names. When the function is called, a string is passed as an 

input argument. The function adds an integer to the end of the string, 

and returns the resulting string. Every time the function is called, the 

integer that it adds is incremented. Here are some examples of calling

the function:

>> createUniqueName('hello')

ans =

hello1

>> varname = createUniqueName('variable')

varname =

variable2

All Answers

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

createUniqueName.m

function newfilename = createUniqueName(instr)

persistent count

if isempty(count)

 count = 0;

end

count = count + 1;

newfilename = strcat(instr,int2str(count));

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