Write a function that concatenated string as output?
2 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
madhan ravi
2019-1-12
编辑:madhan ravi
2019-1-12
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]
2 个评论
madhan ravi
2019-1-12
https://www.mathworks.com/matlabcentral/answers/437732-error-using-ofdm_mod-not-enough-input-arguments#answer_354468 - read about how to use a function
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!