How to write a matrix to a text file
Show older comments
Attached I have the original file "hightemp.txt"
I need to create a script that Converts the text file to a matrix, adds 1900 to the first column, and then writes the matrix to a new text file called "Year2000.txt"
here is what I have tried but it says theres an error
A = dlmread('hightemp.txt');
A(:,1)= A(:,1) + 1900;
dlmwrite('Year2000.txt',A,'delimiter','\t','newline','pc')
also
A = dlmread('hightemp.txt');
A(:,1)= A(:,1) + 1900;
dlmwrite('Year2000.txt',A)
both give me an error on the dlmwrite part (we do not necessarily have to use dlmwrite)
Answers (1)
A = importdata('hightemp.txt') ;
A(:,1) = A(:,1)+1900 ;
dlmwrite('Year2000.txt',A)
2 Comments
Blake shucart
on 18 Sep 2018
KSSV
on 18 Sep 2018
It worked very much in my pc.....use load instead of importdata. YOu should specify error to get help.
Categories
Find more on Text Files in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!