EXCEL2UITABLE:
Steps to import 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.
num=floor(now)-datenum(Text(i,3));
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');
dat=cell(size(Text,1),size(Text,2)+1);
for i=2:size(Text,1)
num=floor(now)-datenum(Text(i,3));
exp=datestr(num,11);
dat(i-1,1)={ID(i-1,1)};
dat(i-1,2)=Text(i,2);
dat(i-1,3)=Text(i,3);
dat(i-1,4)={exp};
end
columnname={'Employee ID','Employee Name','Date Of Join','Experience'};
columnformat = {'numeric', 'char', 'char', 'numeric'};
uitable('Units','normalized','Position',...
[0.1,0.1,.9,.9], 'Data', dat,...
'ColumnName', columnname,...
'ColumnFormat', columnformat,'RowName',[]);
0 comments:
Enjoyed Reading? Share Your Views