From: Susan on 12 Jan 2010 18:14 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <hiiqu4$k7e$1(a)fred.mathworks.com>... > Can you give a realistic example of what you are trying to accomplish by this syntax? Well, here's the most recent scenario, but not the only one: ----- Base workspace - holds a set of variables to be operated on. Due to historical considerations, the variables might have different names. For example var1 might be called A1, A2, or A3 var2 might be called B1, B2, or B3 etcetera These data names are outside my control. ----- Processing function "procFun" is to operate on variables in the base workspace. I want procFun to call a function that assigns them to local variable names. So by calling assignVars, the following would be achieved in the procFun workspace. Either a=A1; b=B1; or a=A2; b=B2; or a=A3; b=B3; etcetera. Following Bruno's advice, I could call another function to sort out the variable names prior to calling procfun, then pass in the data. I could make this work. But there are still some situations that a recursive evalin function would be very helpful. ------ So finally, I want the function assignVars to reach up into the base workspace and make assignments in the procFun workspace. I don't have any trouble programming this, except for the non-recursion limitation on evalin(); ------ I'll look into nested functions. I'm still interested in other ideas, though.
From: Susan on 12 Jan 2010 18:18 "Matt Fig" <spamanon(a)yahoo.com> wrote in message <hiitkc$c7m$1(a)fred.mathworks.com>... > Maybe I missed the point of the limitation, but copying and pasting from the documentation, gives ... You have to use this in the context of subroutines for the limitation to make sense. For example, paste the following in to an m-file and run it: function Afn() format compact; Adata = 1; Bfn; function Bfn() Bdata = 2; disp('Adata value from Bfn:'); evalin('caller','Adata') Cfn; function Cfn() disp('Bdata value from Cfn:'); evalin('caller','Bdata') disp('Adata value from Cfn:'); evalin('caller','evalin(''caller'',''Adata'')');
From: Matt J on 12 Jan 2010 18:47 "Susan " <foowidget(a)gmail.com> wrote in message <hiivvc$9oc$1(a)fred.mathworks.com>... > "Matt Fig" <spamanon(a)yahoo.com> wrote in message <hiitkc$c7m$1(a)fred.mathworks.com>... > > Maybe I missed the point of the limitation, but copying and pasting from the documentation, gives ... > > You have to use this in the context of subroutines for the limitation to make sense. For example, paste the following in to an m-file and run it: > > function Afn() > format compact; > Adata = 1; > Bfn; > > > function Bfn() > Bdata = 2; > disp('Adata value from Bfn:'); > evalin('caller','Adata') > Cfn; > > > function Cfn() > disp('Bdata value from Cfn:'); > evalin('caller','Bdata') > disp('Adata value from Cfn:'); > evalin('caller','evalin(''caller'',''Adata'')'); ==================== OMG not only does that sample code result in an error message, but it permanently throws my display() function out of whack. Notice below that the data is displayed to the screen without the usual line-skipping. Only by restarting MATLAB was I able to fix this. >> a=1 a = 1 >>
From: Susan on 12 Jan 2010 19:09 > OMG not only does that sample code result in an error message, but it permanently throws my display() function out of whack. Notice below that the data is displayed to the screen without the usual line-skipping. Only by restarting MATLAB was I able to fix this. > > >> a=1 > a = > 1 > >> That was because of the "format compact" statement. "format loose" will fix it. You like the line skipping?
From: Matt Fig on 13 Jan 2010 01:02 "Susan " <foowidget(a)gmail.com> wrote in message > You have to use this in the context of subroutines for the limitation to make sense. For example, paste the following in to an m-file and run it: > > function Afn() > format compact; > Adata = 1; > Bfn; > > > function Bfn() > Bdata = 2; > disp('Adata value from Bfn:'); > evalin('caller','Adata') > Cfn; > > > function Cfn() > disp('Bdata value from Cfn:'); > evalin('caller','Bdata') > disp('Adata value from Cfn:'); > evalin('caller','evalin(''caller'',''Adata'')'); Interesting. When the argument to the last EVALIN in Cfn is evaluated in Bfn, Cfn is treated as the caller. I guess you should use nested functions, or a nasty GLOBAL mess or nastier EVALIN the base for all.
First
|
Prev
|
Next
|
Last
Pages: 1 2 3 4 Prev: Hydraulic Pump transfer function. Next: using rough sets for noise filtering |