Info

この質問は閉じられています。 編集または回答するには再度開いてください。

Combine files into a CSV

2 ビュー (過去 30 日間)
Ian
Ian 2015 年 1 月 14 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
I need to combine 3 files into a CSV, the 3 files do not contain the same number of rows there are also ASCII in the 3 files. Below is an example of the 3 files:
File 1
Apple,1
Orange,3
Banana,4
File 2
Orange,10
Banana,7
File 3 Banana,20
Output
Apple,1,Orange,10,Banana,20
Orange,3,Banana,7
Banana,4
Please advice and Thank you.

回答 (1 件)

Sean de Wolski
Sean de Wolski 2015 年 1 月 14 日
doc dir
doc fopen
doc fgetl
doc fprintf
doc fclose
Use dir to find the three files to read. Fopen the files for reading and a new file for writing. Loop over each line in the reading files with fgetl, fprintfing the read to the new file. clean up at the end.
  3 件のコメント
Ian
Ian 2015 年 1 月 14 日
I am sorry, I dint check the preview outcome. Had to press double enter for a new line please advice again thanks
Sean de Wolski
Sean de Wolski 2015 年 1 月 14 日
There's nothing to change, the steps are the same...
Also, you can doubly indent a line to force new line
Hello (two spaced before H)
world

この質問は閉じられています。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by