Write a function that concatenated string as output?

19 ビュー (過去 30 日間)
Brain Adams
Brain Adams 2019 年 1 月 12 日
コメント済み: madhan ravi 2019 年 1 月 12 日
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.

採用された回答

madhan ravi
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 件のコメント
Brain Adams
Brain Adams 2019 年 1 月 12 日
編集済み: Brain Adams 2019 年 1 月 12 日
thank you for the answer. but i need a function that do this process for every different words. 'hello world' is just a example. it could be 'hi there' etc.
for your last answer : What I need to write is a function. What you write is not a function. i need [output] = concantecater(input1,input2) format. and when i use this function for any 2 words; function should be concatenated strings as output.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by