From: Gauri on

> How did you open it? How are you interacting to do the editing? Show
> work...
>
> --function publish_all
listfiles=dir('*.m');
nooffiles=size(listfiles,1);
if(~exist('helpfolder','dir'))
mkdir('helpfolder')
end
for i=1:nooffiles
flag=strcmp(listfiles(i).name,'publish_all.m')
if flag==0
h=help(listfiles(i).name)
hb=regexprep(h,'\n','\n%')
cd helpfolder
edit(listfiles(i).name)
fid=fopen(listfiles(i).name,'w')
fprintf(fid,'%s','%%')
fprintf(fid,'%s',hb)

publish(listfiles(i).name);
close all
cd ../
end
end
From: us on
"Gauri " <bhagwat.gau(a)gmail.com> wrote in message <i0crok$bj2$1(a)fred.mathworks.com>...
> Is there a keyword to close a m-file, just like close all to close all figure files?
>
> Thanks
> Gauri

one of the solutions

fnam=which('unique');
edit(fnam);
ed=com.mathworks.mlservices.MLEditorServices;
disp('press any key to continue');
pause;
ed.closeDocument(fnam);

us
From: Gauri on
"us " <us(a)neurol.unizh.ch> wrote in message <i0ct99$m66$1(a)fred.mathworks.com>...
> "Gauri " <bhagwat.gau(a)gmail.com> wrote in message <i0crok$bj2$1(a)fred.mathworks.com>...
> > Is there a keyword to close a m-file, just like close all to close all figure files?
> >
> > Thanks
> > Gauri
>
> one of the solutions
>
> fnam=which('unique');
> edit(fnam);
> ed=com.mathworks.mlservices.MLEditorServices;
> disp('press any key to continue');
> pause;
> ed.closeDocument(fnam);
>
> us

Thank you
Gauri
From: dpb on
Gauri wrote:
>
>> How did you open it? How are you interacting to do the editing? Show
>> work...
....

> for i=1:nooffiles
> flag=strcmp(listfiles(i).name,'publish_all.m')
> if flag==0
> h=help(listfiles(i).name)
> hb=regexprep(h,'\n','\n%')
> cd helpfolder edit(listfiles(i).name)
> fid=fopen(listfiles(i).name,'w')
> fprintf(fid,'%s','%%')
> fprintf(fid,'%s',hb)
>
> publish(listfiles(i).name);

> % close all

fid = fclose(fid);

> cd ../
> end
> end

--
From: dpb on
dpb wrote:
> Gauri wrote:
....

>> fid=fopen(listfiles(i).name,'w')

OBTW1 -- I suggest getting in habit of using the 't' text option for
text files. Doesn't matter on some platforms but on others it does.
Never hurts...

fid=fopen(listfiles(i).name,'wt');

....

> fid = fclose(fid);
....

OBTW2 --
You're leaving a bunch of open files and losing their handles the way
the loop you have is structured. Since it appears you're not using but
a single file at a time I recommend the above to close each when done,
releasing the handle and then it's ok to reuse.

If one needs more than one at a time then it would become imperative to
keep an array of fid() and address the proper one.

There is the 'all' option in fclose() to close all open file handles but
it is, in general a sloppy way to go at things.

I recommend

doc fopen
doc fclose

--