%% READING AN EXCEL SPREADSHEET IN MATLAB
% Language : Matlab 2008a
% Authors : Autar Kaw
% Last Revised : December 12, 2010
% Abstract: This program shows you how to read an excel file in MATLAB
% The example has student numbers in first column and their score in the
% second column
clc
clear all
disp('This program shows how to read an excel file in MATLAB')
disp('Matlab 2008a')
disp('Authors : Autar Kaw')
disp('Last Revised : December 12, 2010')
disp('http://numericalmethods.eng.usf.edu')
disp(' ')
%% INPUTS
% We have two column data and it has headers in the first row.
% That is why we read the data from A2 to B32.
A=xlsread('c:\users\grades.xls','A2:B32');
disp ('The data read from the excel spreadsheet is')
disp(A)
disp(' ')
%% SOLUTION
% Finding the number of rows and columns
sizem=size(A);
rows_A=sizem(1);
cols_A=sizem(2);
% Assigning the scores to a vector called score
for i=1:1:rows_A
score(i)=A(i,2);
end
% Using the max command to find the maximum score
% HW: Write your own function "max"
maxscore=max(score);
% Finding which student got the highest score
for i=1:1:rows_A
if score(i)==maxscore
student_no=i;
break;
end
% HW: What if more than one student scored the highest grade??
end
%% OUTPUT
disp(' ')
disp ('OUTPUT')
fprintf('Student Number# %g scored the maximum score of %g',...
student_no,maxscore)
disp(' ')