Path: news.mathworks.com!not-for-mail
From: "ragab Rabeiy" <r_rabeiy@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: xlswrite
Date: Fri, 16 Oct 2009 08:01:33 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 73
Message-ID: <hb998t$fo2$1@fred.mathworks.com>
References: <hb6s4f$evt$1@fred.mathworks.com> <hb7104$dus$1@fred.mathworks.com> <5e9ea19c-a0c8-4ea8-a8ce-41222bdbe88f@y21g2000yqn.googlegroups.com>
Reply-To: "ragab Rabeiy" <r_rabeiy@yahoo.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1255680093 16130 172.30.248.35 (16 Oct 2009 08:01:33 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 16 Oct 2009 08:01:33 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2041704
Xref: news.mathworks.com comp.soft-sys.matlab:577748


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <5e9ea19c-a0c8-4ea8-a8ce-41222bdbe88f@y21g2000yqn.googlegroups.com>...
> 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.
Hello ImageAnalyst, your code is working, thank you.
but it gives me three exile files. 

When i made the attached code, it gave me 50 files, each one has its iteration value. so, i need all the results to be in a unique file also in a unique sheet. 
May you have a suggestion.

 
folder ='D:\work';
for n=1:50;
    File=sprintf('Test%d.xls',n);
    if~exist(folder,'dir');  mkdir(folder); end
    m=n*pi;
    fileName=fullfile(folder,File);
    xlswrite(fileName,m);
end

Regards
Ragab