Combine multiple txt files into one single file with index
1 回表示 (過去 30 日間)
古いコメントを表示
I have five output txt files (Apple, Bean, Carrot, Tomato, and Orange) with one column and index as it shown below:
And now I need to combine this single column output file into multiple files as one output file in txt form and have the following output file with the following index and column:
How can I do that?
2 件のコメント
Cedric
2015 年 10 月 1 日
編集済み: Cedric
2015 年 10 月 1 日
Try using TEXTSCAN to read your files. Something like:
fNames = {'file1.txt', 'file2.txt', .. } ;
data = cell( size( fNames )) ;
for k = 1 : numel( fNames )
fId = fopen( fNames{k}, 'r' ) ;
content = textscan( fId, '%s' ) ;
data{k} = content{1} ;
fclose( fId ) ;
end
Work on this until it loads the data properly and see if you can build the output from this data cell array (and e.g. my answer to one of your previous questions).
回答 (1 件)
Madhav Rajan
2015 年 10 月 1 日
I understand that you want to import files based on index. You can use the import tool by right clicking on one text file and importing the data into a cell array of type text. You can specify the format and generate a function for one file. Then you can call this function for all files in a for loop.
You can access the elements of the cell using the '{}' notation. You can then restructure the cells in the appropriate way and concatenate the columns of the other files together into one variable. Then you can save the data to a file in MATLAB.
You can refer the following links for more information: http://www.mathworks.com/help/matlab/ref/importtool-app.html http://www.mathworks.com/help/matlab/ref/cell.html
Hope this helps.
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!