How to merge .txt files from a loop using writematrix

2 views (last 30 days)
Hello,
I have a problem with a code. I am making via aloop multiple .txt files. I would like to merge them to a final.txt file, via a for loop but I do not know how.
I am importing my code
for n=1:numel(st);
for i=1:size(nam);
FP=fopen(sprintf('m%g0.txt',i),'wt');
fprintf(FP,'%s\t',num2str(Results));
fclose(FP);
D = 'absolute/relative path to where the files are saved';
N = 25; % number of files
C = cell(1,N);
for k = 1:N
F = fullfile(D,sprintf('m%u.txt',k));
C{k} = dlmread(F);
end
M = vertcat(C{:});
FF = sprintf('final%u.txt',n);
dlmwrite(FF,M,'\t')
end
end
I have tried dlmwrite but it does not work.
command window shows me error:
Error using dlmread (line 62) The file 'C:\Users\HP\Desktop\P\m2.txt' could not be opened because: No such file or directory
Error in F (line 105) C{k} = dlmread(F);
Could you help me?

Answers (0)

Community Treasure Hunt

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

Start Hunting!