command to merge .txt files

조회 수: 4 (최근 30일)
Ivan Mich
Ivan Mich 2020년 6월 10일
댓글: Ameer Hamza 2020년 6월 11일
Hello,
I have multiple .txt files. Every .txt files has 1 row and 4 columns. I would like to merge these many files to one .txt file , with vertical format.
I use these commands in my code
txtFiles = dir('*.txt') ; % get the text files in the present folder
N = length(txtFiles) ; % Total number of text files
iwant = cell(N,1) ; % initlaize the data required
% loop for each file
for i = 1:N
thisFile = txtFiles(i).name ;
iwant{i} = importdata(thisFile) ; % read data of the text file
end
iwant = cell2mat(iwant) ;
but command window shows me an error:
Error using importdata (line 10)
Unable to load file.
Use readtable for more complex formats.
Caused by:
Index exceeds the number of array elements (1).
could anyone help me?
I am importing one .txt file in order to understand
  댓글 수: 8
Ivan Mich
Ivan Mich 2020년 6월 10일
KSSV I have Imported my file1.txt
Ameer Hamza
Ameer Hamza 2020년 6월 11일
As Stephen mentioned, you should avoid printing the NULL in the first place. You are probably trying to print numeric values as text values. Try the following line to create the text files
fprintf(fid,'%f\t',St{j},R1,b,2)

댓글을 달려면 로그인하십시오.

답변 (0개)

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by