Got Questions? Get Answers.
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Matlab to Excel issue

Subject: Matlab to Excel issue

From: m. k

Date: 24 Sep, 2007 23:43:19

Message: 1 of 5

I am having this issue in MatLab that I hope I can get help
on.

Here is my basic M-file program functions:
1. load excel document
2. read specified sheet in excel document
3. save specific [rxc] matrix from excel sheet to a matlab
variable
4. write [rxc] matrix from matlab variable to a specified
region of same excel document

(if anybody needs further details (i.e. calls used, cmds
used…) on this process, let me know and I will surely
provide them)

The issue is this. When I run my code, the program takes a
while to process everything. And usually the matrices that
I work with in MatLab are on the order of [384x7] in size.
My code works, because I have seen the results saved in
MatLab. However the warning that I always get when the
program is around 2/3 complete is:

Warning: could not start Excel server for export.
XLSWRITE attempts to file in CSV format.

> In xlswrite at 157
> In det_update_decision at 141

(NOTE: 'det_update_decision' is the m-file I wrote, and
line 141 only containes the cmd 'end'.)

I feel that this is an Excel memory-related issue.
Everytime I run my program and it stops due to the above
error, I check the task manager and there are several (>30)
instances of EXCEL.EXE*32's running each taking up ~20,000K
of space in Mem Usage.

Does anybody know what is causing this? And if so, how to
remedy it?

One thing that I tried to do was use the following:

Excel = activexsrv('Excel.Application') to start up an
activexsrv for Excel, and use Excel.Quit at the end of the
code so that I do not have recurring instances of Excel
open in the Task Manager. Is this the correct way to go
about it?

Thanks!
m.k.

Subject: Matlab to Excel issue

From: Yair Altman

Date: 25 Sep, 2007 00:52:17

Message: 2 of 5

> The issue is this. When I run my code, the program takes a
> while to process everything. And usually the matrices that
> I work with in MatLab are on the order of [384x7] in size.
> I feel that this is an Excel memory-related issue.

xlswrite is very inefficient, in that it does not reuse
existing open XLS server COM connections - it reopens a new
connection with each invocation. This takes a lot of time
and system memory, especially if you run the command in a
loop. I suggest you use xlswrite1 or officedoc, both on the
File Exchange, which reuse open connections. There are a few
other alternatives on the FEX - search around.

> Everytime I run my program and it stops due to the above
> error, I check the task manager and there are several (>30)
> instances of EXCEL.EXE*32's running each taking up ~20,000K
> of space in Mem Usage.
>
> Does anybody know what is causing this? And if so, how to
> remedy it?

xlswrite crashed without bothering to close the open COM
connections... You have no access to these connections and
must delete them via the Task Manager.

> One thing that I tried to do was use the following:
>
> Excel = activexsrv('Excel.Application') to start up an
> activexsrv for Excel, and use Excel.Quit at the end of the
> code so that I do not have recurring instances of Excel
> open in the Task Manager. Is this the correct way to go
> about it?

Yes. You can edit/type xlswrite or xlswrite1 to get started,
or simply use one of the aforementioned FEX submissions.

Yair Altman
http://ymasoftware.com

Subject: Matlab to Excel issue

From: Pete sherer

Date: 25 Sep, 2007 04:19:28

Message: 3 of 5

try WRITE2EXCEL

Subject: Matlab to Excel issue

From: m. k

Date: 25 Sep, 2007 21:12:45

Message: 4 of 5

"Yair Altman" <altmanyDEL@gmailDEL.comDEL> wrote in message
<fd9m41$68t$1@fred.mathworks.com>...
> > The issue is this. When I run my code, the program
takes a
> > while to process everything. And usually the matrices
that
> > I work with in MatLab are on the order of [384x7] in
size.
> > I feel that this is an Excel memory-related issue.
>
> xlswrite is very inefficient, in that it does not reuse
> existing open XLS server COM connections - it reopens a
new
> connection with each invocation. This takes a lot of time
> and system memory, especially if you run the command in a
> loop. I suggest you use xlswrite1 or officedoc, both on
the
> File Exchange, which reuse open connections. There are a
few
> other alternatives on the FEX - search around.
>
> > Everytime I run my program and it stops due to the
above
> > error, I check the task manager and there are several
(>30)
> > instances of EXCEL.EXE*32's running each taking up
~20,000K
> > of space in Mem Usage.
> >
> > Does anybody know what is causing this? And if so, how
to
> > remedy it?
>
> xlswrite crashed without bothering to close the open COM
> connections... You have no access to these connections and
> must delete them via the Task Manager.
>
> > One thing that I tried to do was use the following:
> >
> > Excel = activexsrv('Excel.Application') to start up an
> > activexsrv for Excel, and use Excel.Quit at the end of
the
> > code so that I do not have recurring instances of Excel
> > open in the Task Manager. Is this the correct way to
go
> > about it?
>
> Yes. You can edit/type xlswrite or xlswrite1 to get
started,
> or simply use one of the aforementioned FEX submissions.
>
> Yair Altman
> http://ymasoftware.com
>

Thanks Yair. I have found the xlswrite1 on the FEX and
have attempted to use it via the insructions. However, I
am receiving the following error:

------------------------------------------------------------
??? Error using ==> xlswrite1
No appropriate method or public field sheets for class
handle.

Error in ==> m_file_name at 103
xlswrite1('file_name',1,'sheet_name',range);
------------------------------------------------------------

Does this mean that I am invoking the xlswrite1 function
wrong?

As it is now, at the beginning of my mfile I include (word
for word):
------------------------------------------------------------
Excel = actxserver ('Excel.Application');
File='C:\M_files\M_file';

if ~exist(File,'file')
   ExcelWorkbook = Excel.workbooks.Add;
   ExcelWorkbook.SaveAs(File,1);
   ExcelWorkbook.Close(false);
end

invoke(Excel.Workbooks,'Open',File);
------------------------------------------------------------

And at the end, word for word:
------------------------------------------------------------
invoke(Excel.ActiveWorkbook,'Save');
Excel.Quit
Excel.delete
clear Excel
------------------------------------------------------------

In addition, where do I store the M-file xlswrite1? Do I
copy the syntax and append it at the end of my code (which
I tried but it doesnt seem to work), or do I save it in the
same folder as the M-file that I'm writing?

Thanks.

Subject: Matlab to Excel issue

From: Yair Altman

Date: 26 Sep, 2007 06:48:27

Message: 5 of 5

> I have found the xlswrite1 on the FEX and
> have attempted to use it via the insructions. However, I
> am receiving the following error: <...>
> Does this mean that I am invoking the xlswrite1 function
> wrong?
> In addition, where do I store the M-file xlswrite1? Do I
> copy the syntax and append it at the end of my code (which
> I tried but it doesnt seem to work), or do I save it in the
> same folder as the M-file that I'm writing?


I suggest you read the function help documentation and/or
contact the author

Yair

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us