MATLAB: Write a function that concatenated string as output

functionstrings

Hello everyone. I have easy question about strings and functions. I want to write function named concatenater that takes 2 strings as input and returns the concatenated string as output. When the function is done, for ex. i will write :
concatenater('hello','world')
and the program will return that :
ans =
hello world
I would be glad if you help.

Best Answer

a='hello';
b='world';
output = concantecater(a,b) % function call
function output = concantecater(input1,input2) % function definition
output=sprintf('%s %s',input1,input2); % works for any strings
end
Gives:
output =
hello world
a='hi';
b='there';
sprintf('%s %s',a,b)
Gives:
ans =
'hi there'
Or:
[a,' ',b]