From: Etienne ARNAL on 9 Apr 2010 09:47 Hello, I am programming some nested function with this kind of spirit: tool = myTool() data = []; tool = struct('getdata', @getdata, 'setdata', @setdata); function setdata(in) data=in; end function out = getdata() out = data; end end Now I am in Simulink. My 'tool' variable is in my MATLAB Workspace and I want to access to 'Data' value with its nested functions. For getting 'Data' I put a 'Constant' bloc with value 'tool.getData()' and it's well running ! But for setting 'Data' from Simulink with tool.setData(value), I don't know what to do... Have you got an idea ? Thanks
From: Saurabh Mahapatra on 9 Apr 2010 14:58 Hi there, I am not sure what you are trying to do but I would recommend doing this- use the MATLAB Fcn block from the User-Defined Functions library. Click on it and use the following as the MATLAB function: tool.setdata(u). Set the output dimensions to zero to get rid of the outport. If you take a constant block with a value=5 and feed it into this block, you will be able to set the "data" variable. To see if it really worked, try this at the MATLAB Command Prompt: >>tool.getdata() Please keep in mind that since you are setting and reading "data" values, your algorithm(for whatever you are trying to do) must be mutually exclusive between these two operations in any simulation or else risk data corruption. I recommend that you build that logic into your model. If you did eventually have to do that, then why not use a simple variable "data" in the workspace and get rid of all these nested functions(the logic for get and set is in the model itself) Thanks, Saurabh
From: Etienne ARNAL on 13 Apr 2010 04:28 Unfortunalely it is not working. Because variable tool created before the simulation with tool = MyTool() is known in the base workspace. During the simulation, the MATLAB Fcn block create his own workspace and had not access to the base workspace (where tool is known). Maybe it will work with evalin('base','tool.setdata(u)'); "Saurabh Mahapatra" <saurabh.mahapatra(a)mathworks.com> wrote in message <hpntbs$1l1$1(a)fred.mathworks.com>... > Hi there, > > I am not sure what you are trying to do but I would recommend doing this- use the MATLAB Fcn block from the User-Defined Functions library. Click on it and use the following as the MATLAB function: tool.setdata(u). Set the output dimensions to zero to get rid of the outport. > > If you take a constant block with a value=5 and feed it into this block, you will be able to set the "data" variable. To see if it really worked, try this at the MATLAB Command Prompt: > > >>tool.getdata() > > Please keep in mind that since you are setting and reading "data" values, your algorithm(for whatever you are trying to do) must be mutually exclusive between these two operations in any simulation or else risk data corruption. I recommend that you build that logic into your model. If you did eventually have to do that, then why not use a simple variable "data" in the workspace and get rid of all these nested functions(the logic for get and set is in the model itself) > > Thanks, > > Saurabh
|
Pages: 1 Prev: Contourf values specification Next: Convert 3D image to 2D image |