Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

Excel file to matlab


Method: 1
The data from excel file can be imported to matlab using xlsread function.

[numericdata,stringdata]=xlsread(filename, sheet name);

 The numeric data in the sheet will be stored in the first variable ‘numericdata’.

The strings or characters in the sheet will be stored in the second variable ‘stringdata’.

Method : 2
  Using uiimport , the user can interactively select the rows and data.
Syntax: uiimport('Employee.xls')

Sample program:
Here, a excel file by name ‘Employee.xls’ with sheet name ‘Employee Details’ contains some employee details. The details are imported from excel to matlab.

To obtain the heading of each column:
%[data heading]=xlsread('Employee.xls','Employee Details','A1:B1:C1');

[ID Text]=xlsread('Employee.xls','Employee Details');

The numeric and string data are stored in the ID and Text respectively.

To display the sheet in a table format:
The employee id,employee name and employee date of join is stored.
To calculate the experience of each employee, the date of join obtained is converted to datenum and it is subtracted from the current date.
The number of years is obtained by using the function datestr(num,11);
Here the value 11 will return the years in ‘YY’ format.

f = figure('Position',[400 400 400 150],'Name','Employee Details','NumberTitle','off');
for i=2:size(Text,1)

columnname={'Employee ID','Employee Name','Date Of Join','Experience'};

columnformat = {'numeric', 'char', 'char', 'numeric'};

            [0.1,0.1,.9,.9], 'Data', dat,...
            'ColumnName', columnname,...
            'ColumnFormat', columnformat,'RowName',[]);

like button Like "IMAGE PROCESSING" page


Enjoyed Reading? Share Your Views

Previous Post Next Post Home
Related Posts Plugin for WordPress, Blogger...
Google ping Hypersmash.com