Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!y21g2000yqn.googlegroups.com!not-for-mail
From: ImageAnalyst <imageanalyst@mailinator.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: xlswrite
Date: Thu, 15 Oct 2009 13:20:46 -0700 (PDT)
Organization: http://groups.google.com
Lines: 59
Message-ID: <5e9ea19c-a0c8-4ea8-a8ce-41222bdbe88f@y21g2000yqn.googlegroups.com>
References: <hb6s4f$evt$1@fred.mathworks.com> <hb7104$dus$1@fred.mathworks.com> 
	<6d40011a-0172-4478-b67c-04c9e03d6aac@a31g2000yqn.googlegroups.com> 
	<hb7kcp$l5q$1@fred.mathworks.com>
NNTP-Posting-Host: 192.44.136.113
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1255638047 9934 127.0.0.1 (15 Oct 2009 20:20:47 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 15 Oct 2009 20:20:47 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: y21g2000yqn.googlegroups.com; posting-host=192.44.136.113; 
	posting-account=0rLUzAkAAABojYSRC64DkTbtiSCX77HH
User-Agent: G2/1.0
X-HTTP-Via: 1.1 bdci2px (NetCache NetApp/6.0.7)
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; 
	CyberSafe-IWA-Enable; .NET CLR 1.1.4322; .NET CLR 2.0.50727; MS-RTC LM 8; 
	.NET CLR 3.0.04506.648; .NET CLR 3.5.21022),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:577663


On Oct 15, 12:59 pm, "ragab Rabeiy" <r_rab...@yahoo.com> wrote:
> ImageAnalyst <imageanal...@mailinator.com> wrote in message <6d40011a-0172-4478-b67c-04c9e03d6...@a31g2000yqn.googlegroups.com>...
> > ragab Rabeiy
> > Just use sprintf() to create a brand new filename each iteration of
> > the loop and then write out that uniquely-named file, rather than
> > overwriting the same file ("test.xls") each time.  For example
>
> > baseFileName = sprintf('Test %d.xls', j);
> > folder = 'c:\my output folder';
> > if ~exist(folder, 'dir')
> >     mkdir(folder);
> > end
> > fullFileName = fullfile(folder, baseFileName);
> > xlswrite(fullFileName);
>
> > Regards,
> > ImageAnalyst
>
> thank you ImageAnalyst,
> your example seems to be helpful, but i can not understand it. I tried it many times but gave may error also. could you please write a simple one , by which i can make copy and past in command window and it works directly, like
>
> ????
> for n=1:5,
> m=n*pi
> end
> xlaswrite.......????
>
> regards
> ragab- Hide quoted text -
>
> - Show quoted text -

------------------------------------------------------------------------------------------------------------------------------------------
Hmmmmm....  It's really not that hard.  Nonetheless, I did this code
for you:
folder = 'C:\Program Files\MATLAB\work';
for loopIndex = 1:3
	baseFileName = sprintf('Test %d.xls', loopIndex);
	if ~exist(folder, 'dir')
		mkdir(folder);
	end
	dataArray = rand(20, 10);
	fullFileName = fullfile(folder, baseFileName);
	xlswrite(fullFileName, dataArray);
end

It works, though it's very slow.  You'd be better off using xlswrite1
() from the File Exchange so that you don't have to open and close
Excel at every loop iteration.
Good luck,
ImageAnalyst
P.S. Above you put the xlswrite outside the loop but in your earlier
posting you had it inside the loop, so I'm not sure what's up with
that.