|
Oh my goodness, it actually works. Thanks a million!
"Devdatt Lad" <dlad@mathworks.com> wrote in message <hbkjs3$d9e$1@fred.mathworks.com>...
> Hi Daniel,
>
> Use the following approach with EVALIN:
>
> eml.extrinsic('evalin')
> x = 0;
> x = evalin('base', 'someVar;');
> if x == 42
> ... other stuff
> end
>
> Why do this?
>
> When you use eml.extrinsic, you are telling the EML compiler to not generate
> code for the function 'evalin', but rather, dispatch that call to MATLAB.
> Now, MATLAB returns variables of type 'mxArray'. Thus, the return value from
> 'evalin' is of type 'mxArray'. EML cannot compare an 'mxArray' to the double
> number 42 and hence throws an error.
>
> To resolve this, the return value from 'evalin' should be assigned to a
> variable whos type is already known to the EML compiler. Thus, by saying: x
> = 0; you are telling the EML compiler that the variable 'x' has a type
> 'double' and value 0.
>
> Now, changing the value of x by saying:
>
> x = evalin(...)
>
> does not change the type of x which continues to remain 'double' and now you
> can use this variable in expressions.
>
> See the following doc page for more information:
> http://www.mathworks.com/access/helpdesk/help/toolbox/eml/ug/bq1h2z8-34.html#bq1h2z9-38
>
> Hope this helps,
> Devdatt
>
> ---
> Devdatt Lad
> Discrete-Event Simulation
> The MathWorks, Inc.
>
>
> "Daniel " <ddeibler0001@email.vccs.edu> wrote in message
> news:hbj6u7$n90$1@fred.mathworks.com...
> >I need to use a SimEvents Attribute Function to read the value of a
> >variable in the MATLAB workspace. I'm able to write to it by using the
> >following inside the Attribute Function:
> >
> > eml.extrinsic('assignin');
> > assignin('base','someVar',42);
> >
> > This works fine inside the Attribute Function. The MATLAB workspace
> > variable called 'someVar' gets set to 42. But when I try to do the same
> > with 'evalin' like this:
> >
> > eml.extrinsic('evalin');
> > if evalin('base','someVar') == 42
> > ....(other stuff)...
> >
> > I get an error at "evalin('base',someVar')" that says "Expected either a
> > logical, char, int, fi, single, or double. Found a MATLAB type. MATLAB
> > types are returned from calls to the MATLAB interpreter and are not
> > supported inside expressions. They may be used on the right-hand side of
> > assignments and as arguments to MATLAB calls."
> >
> > What must I do to be able to read the workspace variable I was just able
> > to write from inside an Attribute Function?
>
|