Info

此问题已关闭。 请重新打开它进行编辑或回答。

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

2 次查看(过去 30 天)
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 个评论
Rik
Rik 2020-10-7
The last nested loop can probably be replaced by ismember.

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by