Create a data file to store information on hurricanes. Each line in the file should have the name of the hurricane, its speed in miles per hour, and the diameter of its eye in miles
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:9| Question number:18.9
All Answers
total answers (1)
Ch9Ex18.m
% Reads hurricane information and store in vector
% of structures, print name and area for each
fid = fopen('hurricane.dat');
if fid == -1
disp('File open not successful')
else
i = 0;
while feof(fid) == 0
i = i + 1;
aline = fgetl(fid);
[hname, rest] = strtok(aline);
[speed, diam] = strtok(rest);
hstruc = struct('Name', hname, 'Speed', ...
str2num(speed), 'Diam', str2num(diam));
hurricane(i) = hstruc;
end
for i = 1:length(hurricane)
fprintf('%s had area %.2f\n', hurricane(i).Name, ...
pi * (hurricane(i).Diam/2)^2)
end
closeresult = fclose(fid);
if closeresult == 0
disp('File close successful')
else
disp('File close not successful')
end
end
need an explanation for this answer? contact us directly to get an explanation for this answer