Question

Yr Mnth LowTemp(°F) HighTemp(°F) Precip(in) 89 Feb 53.8 71.6 2.67 89 Mar 58.5 76.3 2.84 89...

Yr    Mnth   LowTemp(°F)  HighTemp(°F)  Precip(in)
89    Feb       53.8          71.6        2.67  
89    Mar       58.5          76.3        2.84       
89    Apr       62.4          80.6        1.80
89    May       68.9          86.3        2.85
: (continues with the same pattern unitl the end of the file) 


Note that only two digits are used for the year (this was common practice in the last century). An example file of this format is provided in temps.txt.zip . (Decompress it to get temps.txt

We are using MATLAB.

Problem 1. Write a program that reads data in this format and creates a new ASCII text file that is equivalent but has the year values converted to be four digit (e.g. 1989). The names of both files should be provided by the user. For example, after being processed by your program, the above data would start with the following lines.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

inp2 = input('Enter input filename:','s');
inp3 = input('Enter output filename:','s');

fileID = fopen(inp2, 'r');
fileID2 = fopen(inp3, 'wt');

i = 0;
nline = fgets(fileID);
tline = nline;
fprintf(fileID2,'%s',tline);
tline = fgets(fileID);
nline = strcat('19',tline);
%fprintf(fileID2,'\n');
while ischar(tline)
fprintf(fileID2,'%s\n',nline);
tline = fgets(fileID);
nline = strcat('19',tline);

end
fclose(fileID);
fclose(fileID2);

Add a comment
Know the answer?
Add Answer to:
Yr Mnth LowTemp(°F) HighTemp(°F) Precip(in) 89 Feb 53.8 71.6 2.67 89 Mar 58.5 76.3 2.84 89...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT