Merging the Data in the Text Files for the Number of "N" Text Files

2 ビュー (過去 30 日間)
tinkyminky93
tinkyminky93 2023 年 1 月 6 日
コメント済み: Vilém Frynta 2023 年 1 月 7 日
Hello,
In my directory I have N numbers of text files and I want to read all of them with the datas that they contain. After that, I want to merge these N text files to just one text file. What I did was finding the text files in the directory and find their names, I could not read them and merge them. Thanks for your help.
clc
clear
close all
directory = 'C:\me\me\Desktop\directory';
fileList = dir(fullfile(directory, '*.txt'));
names_temp = struct2cell(fileList);
text_name = names_temp(1,:);

採用された回答

Vilém Frynta
Vilém Frynta 2023 年 1 月 6 日
Hey,
there's a lot of ways to read text files. For your purposes, I think fileread and fscanf functions might do well.
Then, you can merge them, which depends on the data type that will be output of your reading.
  4 件のコメント
tinkyminky93
tinkyminky93 2023 年 1 月 7 日
When I run this code, it gives me some cell arrays but inside of the cell arrays I see NaN values. Have you got any opinion about it sir? Thanks.
Vilém Frynta
Vilém Frynta 2023 年 1 月 7 日
oh, yes. readmatrix was function that i used to load my data. you should use your method to load the text data. maybe fileread or fscanf as i mentioned above.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLow-Level File I/O についてさらに検索

製品


リリース

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by