フィルターのクリア

how to concat two strings with data from external file inbetween?

5 ビュー (過去 30 日間)
Hugo
Hugo 2021 年 9 月 5 日
回答済み: Paul 2021 年 9 月 5 日
Hi,
I have two strings:
string1='Simpson'
string2='Wilder'
I also have an external text file, called numbers.txt whose content is:
1
11
23
46
76
I would like to read numbers.txt and write the following to an external file, called concat.txt
Simpson,1,Wilder,
Simpson,11,Wilder,
Simpson,23,Wilder,
Simpson,46,Wilder,
Simpson,76,Wilder,
How can I do this in MATLAB?
I thank you in advance,
Best regards,

採用された回答

Pablo J. Rosado Junquera
Pablo J. Rosado Junquera 2021 年 9 月 5 日
To read your input data, you could use the function readmatrix. Then, the function strcat is what you want to use to perform your string operations. The last step would be using writematrix to write down your concat txt file.
Cheers!

その他の回答 (1 件)

Paul
Paul 2021 年 9 月 5 日
One approach, I'm sure there are others:
first = "Simpson";
last = "Wilder";
nums = string(readmatrix('input.txt'));
out = first + "," + nums + "," + last;
writematrix(out,'output.txt','QuoteStrings',false);

カテゴリ

Help Center および File ExchangeString Parsing についてさらに検索

タグ

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by