How to change a specific column to a .txt file by importing data from another .txt file.?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hello,
I have a question about a code. I have two .txt files (I am importing them in order to understand what the format is). Document1.txt has rows and columns of numbers, and "Document2.txt" has only one column with numbers. I would like to change the content of Document1.txt and creating 4 new documents.
The change that I want is to change the numbers of 4th column of "Document1.txt" (I mean the number "70") by the number of first row of column of "Document2.txt" (I mean number "30"). After this change , I would like to create a new .txt file with this change. (Let's call it "Document1_revised.txt"). After goinr to the second row of column of "Document2.txt" and doing the replacement etc..
To sum up I would like via a loop to create txt files by replacing specific thing from one file, and importing data from another file. I am importing the 4 .txt files that I would to create via commands in matlab.
Could anyone help me?
3 commentaires
darova
le 23 Avr 2020
I tell you honestly: i don't want to read all this question, it's too long
Maybe a simple example would help
for i = 1:4
str = sprintf('document %d.txt',i); % file name1 to read
A1 = readtable(str); % load file1
A2 = A1;
A2(:,3) = 2*A2(:,3); % make some change to data
writetable(A2,['new_' str]); % save data2 as new file
end
Réponses (0)
Voir également
Catégories
En savoir plus sur Environment and Settings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!