## Contents

## 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(' ')

This program shows how to read an excel file in MATLAB Matlab 2008a Authors : Autar Kaw Last Revised : December 12, 2010 http://numericalmethods.eng.usf.edu

## 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(' ')

The data read from the excel spreadsheet is 1 15 2 21 3 24 4 27 5 15 6 24 7 17 8 20 9 22 10 19 11 19 12 23 13 22 14 26 15 23 16 25 17 18 18 22 19 21 20 19 21 21 22 15 23 18 24 22 25 24 26 17 27 18 28 19 29 27 30 24 31 20

## 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(' ')

OUTPUT Student Number# 4 scored the maximum score of 27