% Usage : xlswrite(A)
function xlswrite(A)
[newmatfile, newpath] = uiputfile('*.xls', 'Save As');
filename = [newpath,newmatfile];
if isempty(findstr([newpath,newmatfile],'.xls')) 
   filename = [filename,'.xls'];
end
excel = actxserver('Excel.Application');
%excel.Visible = 1;
wb = invoke(excel.Workbooks,'Add');
sh = excel.ActiveWorkBook.Sheets;
sh2 = get(sh, 'Item', 1);
invoke(sh2, 'Activate');
ash = excel.Activesheet;
Asize=size(A);
Endpoint=sprintf('%c%d',char(Asize(2)+64),Asize(1));
ashrange = get(ash,'Range','A1',Endpoint);
set(ashrange, 'Value', A);
invoke(wb, 'SaveAs', filename);
wb.Saved = 1;
invoke(wb, 'Close');
invoke(excel, 'Quit');
delete(excel);
