How to write a matrix to a text file

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)

KSSV
KSSV on 18 Sep 2018
Edited: KSSV on 18 Sep 2018
A = importdata('hightemp.txt') ;
A(:,1) = A(:,1)+1900 ;
dlmwrite('Year2000.txt',A)

2 Comments

that also didn't work, there was an error with the import data command
It worked very much in my pc.....use load instead of importdata. YOu should specify error to get help.

Sign in to comment.

Asked:

on 18 Sep 2018

Commented:

on 18 Sep 2018

Community Treasure Hunt

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

Start Hunting!