Prev: How to Install DSP kit
Next: subsystem name list
From: Kate J. on 16 Feb 2010 13:32 I have an m-file generated by GUIDE that controls the operations of my gui. Another component of my system is a Simulink model that contains a C-MEX s-function block (which is defined by level-2 s-function c code, which I turn into a mex file that is called by this block). I need for both of these files (GUIDE m-file & C-MEX s-function/Level-2 s-function C file) to share certain variables (e.g. when a user inputs data to the gui, I’d like this value to be immediately accessible within the C-MEX s-function, even though this value is initially being read in by the GUIDE m-file.) As far as I know, I have 3 options: a) use global variables --> I tried this, but it appears that each piece of code only recognizes the global variable declared within itself – i.e., these variables don’t actually appear to be very “global.” Am I missing something? Is there a way for both files to share certain variables, so that each time the variable’s value changes, the new value will be updated in both files? b) There is a more complex method that is supposed to work, which involves nested functions, function handles, and persistent variables. This method is very complex, and the potential for bugs and errors is discouraging, so I’m trying to see if there is a simpler way to do this variable-sharing before I go this route. c) I have successfully passed values from the m-file to the c-file (indirectly, by routing them from the GUIDE m-file to the Matlab workspace and then to the Simulink model, where they are then passed into the C-MEX s-function block) using assignin( ), evalin( ), and set_param( ) functions. However, this method seems to be very slow, and I really need for there to be minimal lag time, as my system needs to run in near-real time. So, unless anyone has suggestions about how I could speed up this clumsy method, I believe it won’t be a good choice to use for my purposes. ** Summary of my question: Is anyone aware of a straightforward way in which I could either share the same variables between my GUIDE m-file & a Level-2 s-function C file (accessed by a block in a Simulink model), or pass variables/values from one of these files to the other in a fast, efficient, simple way? I have read through Matlab’s documentation on GUIDE Callback Syntax and Arguments, but this doesn’t appear to mention interaction with outside files, and I haven’t arrived at a way to do this, yet. Thanks in advance for any guidance you can provide!
|
Pages: 1 Prev: How to Install DSP kit Next: subsystem name list |