Thread Subject: open th file immidiately after fprintf

Subject: open th file immidiately after fprintf

From: nico cruz

Date: 9 Feb, 2010 10:22:03

Message: 1 of 4

Hi everybody,

I cant find any solution to execute an m-file script immidiately after creating it with fprintf.

my file looks like this:

S5 = regexprep(S4, '] [', '\n');
fid = fopen('AutoJac.m','w');
S6 = fprintf(fid,'Jac = [%s];',S5);
fclose(fid);
AutoJac

the problem is that matlab cant find the m-file AutoJac. I have to end the file or put a breakpoint to be able to open it.

I tryed fseek and frewind, but i might have done it wrong.

thanx

Subject: open th file immidiately after fprintf

From: h1of4hs

Date: 9 Feb, 2010 10:44:28

Message: 2 of 4

Hello,
a) this is not a minimal example, since S4 is not known!
b) try: run AutoJac

Regards,
h1of4hs

nico cruz schrieb:
> Hi everybody,
>
> I cant find any solution to execute an m-file script immidiately after creating it with fprintf.
>
> my file looks like this:
>
> S5 = regexprep(S4, '] [', '\n');
> fid = fopen('AutoJac.m','w');
> S6 = fprintf(fid,'Jac = [%s];',S5);
> fclose(fid);
> AutoJac
>
> the problem is that matlab cant find the m-file AutoJac. I have to end the file or put a breakpoint to be able to open it.
>
> I tryed fseek and frewind, but i might have done it wrong.
>
> thanx

Subject: open th file immidiately after fprintf

From: nico cruz

Date: 9 Feb, 2010 10:56:03

Message: 3 of 4

S4 is known, I just didnt want to copy the whole file.

but run AutoJac worked!!!

thank you very much

h1of4hs <h2410138@yahoo.de> wrote in message <16fd6054-9dae-43dd-b60e-955177b897e7@q4g2000yqm.googlegroups.com>...
> Hello,
> a) this is not a minimal example, since S4 is not known!
> b) try: run AutoJac
>
> Regards,
> h1of4hs
>
> nico cruz schrieb:
> > Hi everybody,
> >
> > I cant find any solution to execute an m-file script immidiately after creating it with fprintf.
> >
> > my file looks like this:
> >
> > S5 = regexprep(S4, '] [', '\n');
> > fid = fopen('AutoJac.m','w');
> > S6 = fprintf(fid,'Jac = [%s];',S5);
> > fclose(fid);
> > AutoJac
> >
> > the problem is that matlab cant find the m-file AutoJac. I have to end the file or put a breakpoint to be able to open it.
> >
> > I tryed fseek and frewind, but i might have done it wrong.
> >
> > thanx

Subject: open th file immidiately after fprintf

From: Steven Lord

Date: 9 Feb, 2010 14:47:26

Message: 4 of 4


"nico cruz" <m.nicolas.cruz@mailbox.tu-berlin.de> wrote in message
news:hkrd0b$ivm$1@fred.mathworks.com...
> Hi everybody,
>
> I cant find any solution to execute an m-file script immidiately after
> creating it with fprintf.
>
> my file looks like this:
>
> S5 = regexprep(S4, '] [', '\n');
> fid = fopen('AutoJac.m','w');
> S6 = fprintf(fid,'Jac = [%s];',S5);
> fclose(fid);
> AutoJac
>
> the problem is that matlab cant find the m-file AutoJac. I have to end the
> file or put a breakpoint to be able to open it.

I strongly recommend you try another approach. This is begging for trouble
if you put this in a function file, have another file named AutoJac.m on
your path, and do not have an AutoJac.m already in the location where you're
going to create the function at runtime.


function dynamicFunctionCreation
fid = fopen('sin.m', 'wt');
fprintf(fid, 'function y = sin(x)\n');
fprintf(fid, 'y = 5*x;\n');
fclose(fid);
sin(pi)


We recommend that people avoid "poofing" variables into their workspace
because it can cause difficult-to-debug problem ... but you could run into
those same type of problems because you're "poofing" a function into
existence! You might expect the call to sin(pi) on the last line to return
5*pi, but instead it returns the sine of pi radians, as when the function is
parsed MATLAB decides that the instance of sin in dynamicFunctionCreation is
a call to the built-in function that it knows about and it can't "change its
mind" when you create the sin.m function at runtime.

BTW, you'll want to delete the sin.m created by the dynamicFunctionCreation
function once you're finished testing it out, to avoid warnings.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
fprintf nico cruz 9 Feb, 2010 05:24:06
rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com