Info

この質問は閉じられています。 編集または回答するには再度開いてください。

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

2 ビュー (過去 30 日間)
Izem
Izem 2020 年 10 月 6 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
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.
Izem
Izem 2020 年 10 月 7 日
Alright. Thank you and have a good day sir !

回答 (0 件)

Community Treasure Hunt

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

Start Hunting!

Translated by