Info

This question is closed. Reopen it to edit or answer.

How to add data from a text file to another text file ?

1 view (last 30 days)
Izem
Izem on 6 Oct 2020
Closed: MATLAB Answer Bot on 20 Aug 2021
Hello, I want to modify File 2 to File 3 based on File 1. As you can see in the picture attached to this question, some (m,n) values in File 1 does not exist in File 2 so I want to add them with a correction = 0 so that I can get File3.
I tried to write File 2 in a cell and then write it back with the added lines but I don't know how to do it correctly, Here is the first lines of my code if someone can help
mcorrection = str2double(C{1,1});
ncorrection = str2double(C{1,2});
correction = C{1,3};
data=readfile(name);
HeaderLines = 8;
for i=(HeaderLines+1):numel(data)
str=data{i};
vals=textscan(str,' %f %f %f %f %f %f %f %f');
m=vals{1}; n=vals{2};
for j=1:length(correction)
if m == mcorrection(j) && n == ncorrection(j)
A{j} = sprintf('%d %d %f',str2num(C{1,1}{j}),str2num(C{1,2}{j}),str2num(C{1,3}{j}));
else
A{j} = sprintf('%d %d 0.0',str2num(C{1,1}{j}),str2num(C{1,2}{j}));
  16 Comments
Rik
Rik on 7 Oct 2020
The last nested loop can probably be replaced by ismember.

Answers (0)

Community Treasure Hunt

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

Start Hunting!