Read or Write an Excel file in Matlab.

I used a lot of read and write functions in Matlab, xlsread and xlswrite. However when I run it pops up a lot of windows that:
Microsofe Excel has stopped working, and Windows is checking for a solution.
Why it is idle? Thanks.

6 Comments

Probably causing errors? Who knows w/o any more info than that provided?
Can you execute the commands in sequence and isolate a cause? Perhaps you're trying to access a worksheet that's already open and thereby locked? Perhaps there's an actual problem w/ the Excel installation--checked for updates lately?
Hi, I closed the excel file, otherwise it won't let me write a value into Excel.
I do not think it is locked. The error windows happens when I need to write a lot of values into Excel.
W/O code anything is purely speculation...what's "a lot" and how are you writing them--one at a time repeatedly, as an array, ...???
C Zeng
C Zeng on 24 Jul 2013
Edited: C Zeng on 24 Jul 2013
Sorry, I used them in a loop, each time write a value into an Excel file but different cell in excel. Like:(note location cell will not change for different i)
For i=1:N
xlswrite('Validation.xlsx', {value{1}(m)},'Interface Inputs','I22');
xlswrite('Validation.xlsx', {value{1}(m)},'Interface Inputs','I23');
end
For xlsread, yes I used them one at a time repeatedly. Each time read a value from a cell in Excel file, and assign the value to a new variable.
Thanks.
I used them in a loop, each time write a value into an Excel file but different cell in excel. Like:(note location cell will not change for different i)
For i=1:N
xlswrite('Validation.xlsx', {value{1}(m)},'Interface Inputs','I22');
xlswrite('Validation.xlsx', {value{1}(m)},'Interface Inputs','I23');
end
I don't follow--you say a different cell then expressly note that cell location will not change??? Why write the same thing multiple times?
I suspect your loop in Matlab is trying to execute faster than the COM engine can keep up and you're thus "locking up" Excel.
I don't use Excel but as a toy and have never done the link w/ Matlab other than just as an exercise here or at cs-sm for a particular syntax problem or the like so I'm sorta' guessing but--
1) Can you not write an area/block at a time rather than a single cell, and
2) I suggest use the return values from xlswrite() and inspect status and particularly the status message if indicates a failure.
3) If you think you must use the kind of structure you're using, try inserting a short pause in the loop and see if that solves the problem.
Hi, dpb, sorry, I wrote it just as an example, each time I am sure the cell is different. Yes, I use xlswrite commands in a sequence and that may be the cause.
Actually I have to write a cell a time, because they are not in a block or area.
Thanks for your suggestions.

Sign in to comment.

Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products

Asked:

on 24 Jul 2013

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!