In MATLAB:
1) For the functions fscanf and textscan, write a script for each function to compare them.
The first script will read the DATA.txt file by using fscanf and then plot each temperature data monthly.
The second script, which reads DATA.txt file but uses the textscan function, and plot each temperature data monthly.
DATA.txt
ave.temp ave.high.temp ave.low.temp highest.rec.temp lowest.rec.temp Jan 31.60 38.60 24.60 69.00 -4.00 Feb 31.70 39.20 24.30 69.00 -11.00 Mar 39.00 47.10 31.10 83.00 7.00 Apr 48.90 58.20 39.70 95.00 15.00 May 58.90 68.70 49.20 95.00 30.00 Jun 67.80 76.90 58.60 96.00 36.00 Jul 73.10 81.70 64.50 99.00 48.00 Aug 71.90 79.90 63.90 100.00 44.00 Sep 66.00 73.80 58.10 96.00 36.00 Oct 56.10 64.00 48.10 91.00 26.00 Nov 46.00 53.40 38.70 81.00 14.00 Dec 35.70 42.50 29.00 75.00 -7.00
%%first script
%using fscanf
clear
clc
f=fopen('DATA.txt','r');
header=fscanf(f,' %s ',5);
data=zeros(12,5);
for i=1:12
month=fscanf(f,'%s',1);
data(i,:)=fscanf(f,'%f %f %f %f %f',5);
end
fclose(f);
figure
plot(1:12,data)
legend('Ave temp','Ave high temp','ave low temp','highest rec
temp','lowest rec temp')
xlabel('months')
ylabel('Temperature')
title('using fscanf')
%%%%%%%%%%%%%
%second script
%using textscan
clear
clc
f=fopen('DATA.txt','r');
header=textscan(f,'%s %s %s %s %s',1);
data=zeros(12,5);
data1=textscan(f,'%s %f %f %f %f %f');
data(:,1)=(data1{2});
data(:,2)=(data1{3});
data(:,3)=(data1{4});
data(:,4)=(data1{5});
data(:,5)=(data1{6});
fclose(f);
figure
plot(1:12,data)
legend('Ave temp','Ave high temp','ave low temp','highest rec
temp','lowest rec temp')
xlabel('months')
ylabel('Temperature')
title('using textscan')
In MATLAB: 1) For the functions fscanf and textscan, write a script for each function to...