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:
xlswrite

Subject: xlswrite

From: dhuan Du

Date: 11 May, 2009 16:13:01

Message: 1 of 4

Hi, friends:

For some reaons I always get from with this function, xlswrite. I used this fuction in a loop. It will work well for a lot of iterations but sundenly get error information in some iteration. The error information is
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
??? Error using ==> xlswrite at 253
The file N:\Personal\MATLAB\Disastercode\matlab\outputS3.xls is not writable. It
may be locked by another process.
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I really do not know what happen, could some one help me? (Thanks a lot)

The codes are simplied prestented below:

For s=1: Sn

    yxlsname=strcat('yS',int2str(s),'.xls');
    y_avgxlsname=strcat('y_avgS',int2str(s),'.xls');
    wfxlsname=strcat('wfS',int2str(s),'.xls');
    outputxlsname=strcat('outputS',int2str(s),'.xls');
    ymesname=strcat('ymsgS',int2str(s),'.xls');
    
    delete(yxlsname);
    delete(wfxlsname);
    delete(outputxlsname);
    delete(ymesname);

     for wf_n =1: FN
        sheetnamey=strcat('Y_','s',int2str(s),'_Wfn',int2str(wf_n))
        xlswrite (yxlsname, Y{s,wf_n}, sheetnamey);
        xlswrite (yxlsname, uniqueY, strcat('uniqueY', '_Wfn',int2str(wf_n)));
        
        sheetnameyavg=strcat('Y_avg_','s',int2str(s),'_Wfn',int2str(wf_n))
        xlswrite (y_avgxlsname, Y_avg{s,wf_n}, sheetnameyavg);
        xlswrite (y_avgxlsname, uniqueY_avg, strcat('uniqueYavg','_Wfn',int2str(wf_n)));
        
        sheetnamewf=strcat('Wf_','s',int2str(s),'_Wfn',int2str(wf_n))
        xlswrite (wfxlsname, Wf{s,wf_n}, sheetnamewf);
        
    end
    
    xlswrite(outputxlsname, {'s','wf_s','wf_stepsize','wf_e' ;s, wf_s, wf_stepsize, wf_e}, 'readme');
    
       xlswrite(outputxlsname, best_lv2, 'lv2best' );
    
       xlswrite(outputxlsname, lb, 'lb');
    
       xlswrite(outputxlsname, tlevel2, 'tlevel2');

end

Subject: xlswrite

From: ImageAnalyst

Date: 11 May, 2009 18:44:09

Message: 2 of 4

On May 11, 12:13 pm, "dhuan Du" <dupe...@gmail.com> wrote:
> Hi, friends:
>
> For some reaons I always get from with this function, xlswrite. I used th=
is fuction in a loop. It will work well for a lot of iterations but sundenl=
y get error information in some iteration. The error information is
> \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
> ??? Error using ==> xlswrite at 253
> The file N:\Personal\MATLAB\Disastercode\matlab\outputS3.xls is not writa=
ble.  It
> may be locked by another process.
[snip]

---------------------------------------------------------------------------=
-----------------------------------
dhuan Du:
Perhaps it's a timing issue. You definitely don't want to have
xlswrite() in a loop unless you're willing to live with a very very
slow process. Each time it calls xlswrite, it has to launch Excel,
poke your data into it, and then shut down Excel. Most likely it
wasn't done shutting down Excel completely when you tried to launch it
again.

Solution: use xlswrite1() from the file exchange. You manually (by
that I mean with a few lines of code) open Excel, then call xlswrite1
() as many times as you want, then you manually shut down Excel. As a
benefit you will find it much, much faster.
Good luck,
ImageAnalyst

Subject: xlswrite

From: dhuan Du

Date: 12 May, 2009 13:06:02

Message: 3 of 4

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <36a45f47-d8f1-4b82-a30b-847a14bac518@o20g2000vbh.googlegroups.com>...
> On May 11, 12:13?pm, "dhuan Du" <dupe...@gmail.com> wrote:
> > Hi, friends:
> >
> > For some reaons I always get from with this function, xlswrite. I used th=
> is fuction in a loop. It will work well for a lot of iterations but sundenl=
> y get error information in some iteration. The error information is
> > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
> > ??? Error using ==> xlswrite at 253
> > The file N:\Personal\MATLAB\Disastercode\matlab\outputS3.xls is not writa=
> ble. ?It
> > may be locked by another process.
> [snip]
>
> ---------------------------------------------------------------------------=
> -----------------------------------
> dhuan Du:
> Perhaps it's a timing issue. You definitely don't want to have
> xlswrite() in a loop unless you're willing to live with a very very
> slow process. Each time it calls xlswrite, it has to launch Excel,
> poke your data into it, and then shut down Excel. Most likely it
> wasn't done shutting down Excel completely when you tried to launch it
> again.
>
> Solution: use xlswrite1() from the file exchange. You manually (by
> that I mean with a few lines of code) open Excel, then call xlswrite1
> () as many times as you want, then you manually shut down Excel. As a
> benefit you will find it much, much faster.
> Good luck,
> ImageAnalyst


Hi, ImageAnalyst:

I think I reason you pointed out might be right. I will think about to move the xlswrite out of the loop.

Thanks,
dhuan Du

Subject: xlswrite

From: dhuan Du

Date: 12 May, 2009 20:26:01

Message: 4 of 4

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <36a45f47-d8f1-4b82-a30b-847a14bac518@o20g2000vbh.googlegroups.com>...
> On May 11, 12:13?pm, "dhuan Du" <dupe...@gmail.com> wrote:
> > Hi, friends:
> >
> > For some reaons I always get from with this function, xlswrite. I used th=
> is fuction in a loop. It will work well for a lot of iterations but sundenl=
> y get error information in some iteration. The error information is
> > \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
> > ??? Error using ==> xlswrite at 253
> > The file N:\Personal\MATLAB\Disastercode\matlab\outputS3.xls is not writa=
> ble. ?It
> > may be locked by another process.
> [snip]
>
> ---------------------------------------------------------------------------=
> -----------------------------------
> dhuan Du:
> Perhaps it's a timing issue. You definitely don't want to have
> xlswrite() in a loop unless you're willing to live with a very very
> slow process. Each time it calls xlswrite, it has to launch Excel,
> poke your data into it, and then shut down Excel. Most likely it
> wasn't done shutting down Excel completely when you tried to launch it
> again.
>
> Solution: use xlswrite1() from the file exchange. You manually (by
> that I mean with a few lines of code) open Excel, then call xlswrite1
> () as many times as you want, then you manually shut down Excel. As a
> benefit you will find it much, much faster.
> Good luck,
> ImageAnalyst

Hi, ImageAnalyst

Finally, I feel I must include xlswrite in a loop. Could you please show me how to manually (by a few lines of code) to open and shut down Excel?

Thanks a lot!

Du

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