Write a script to read in division codes and sales for a company from a file that has the following format: A 4.2 B 3.9 Print the division with the highest sales
belongs to book: MATLAB: A Practical Introduction to Programming and Problem Solving|Stormy Attaway|Fourth Edition| Chapter number:9| Question number:22.9
All Answers
total answers (1)
Ch9Ex22.m
% Read in company data and print the division with the
% highest sales
fid = fopen('sales.dat');
if fid == -1
disp('File open not successful')
else
%Read in data from file
C = textscan(fid,'%c %f');
[sales, index] = max(C{2}); %Find the max sales and its index
code = C{1}(index);
fprintf('Division %s has the highest sales of %.1f\n',...
code,sales)
%Error-check file close
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