Error displayed : Undefined function or variable 'Tg'

Hello,I am familier with C++. I dont how to use Simulink. I have more than 10 variables which need to be declared only once before start of simulation. Simulation time is appro. 500 sec. I declared them in InitFcn in model explorer.
These variable are 3 dimensional and they are declared Globally in InitFcn and interesting thing is that these variable are shown in the workspace. But these variable are not available in 'Embedded Matlab Function' for futher processing.
Error displayed : Undefined function or variable 'Tg'(one of global variable name) Function 'Embedded MATLAB Function' (#18.38.40), line 3, column 14: "Tg"
Also for local variables of 'Embedded Matlab Function' similar error is displayed.

 Accepted Answer

Even if it is a global variable you still need to add it to your Embedded Function.
Open your Embedded Function, then click Tools -> Edit Data/Ports. From here you need to add your global variable 'Tg' as a parameter.

4 Comments

Now I deleted all the contains of ‘InitFcn’ of model explorer to avoid confusion and decided to initialize them inside Matlab embedded function inside Simulink.
1. I followed the procedure given at this page http://www.mathworks.co.kr/help/toolbox/simulink/ug/bsds2rv.html
When the scope of global variable defined in the matlab embedded function in the Simulink is set to “Data store memory” using the Ports and Data manager it displayed following error. Simulink.Signal object 'epsilon' (Global variable)implies a Data Store Memory block for the model 'PBR_Temp_Xe', so the property 'Dimensions' may not be -1. This error message is related to a hidden DataStoreMemory block.This block is inserted to support a local data store corresponding to the Simulink. Signal object 'epsilon' in the model workspace.
2. According to you when I defined global variable as a “parameter” using the Ports and Data manager ,it displayed following error i) Expression 'Cp' (Global variable) for initial value of data 'Cp' (#62) must evaluate to a numeric or logical. ii) Error reported by S-function 'sf_sfun' in 'PBR_Temp_Xe/Embedded MATLAB Function/ SFunction ':Stateflow Suppress Error In both of the cases the Simulink signal defined in the Base workspace are shown as Matlab workspace.
What to do in this regard ?
Expression 'Cp' (Global variable) for initial value of data 'Cp' (#62) must evaluate to a numeric or logical.
That error should be pretty clear. Remember that Simulink doesn't support char arrays or similar. As for the Data Store Memory question, well, I can't help you with that since I've never them - having various function blocks access a global variable isn't exactly what I would consider a good idea.
How do you solved it?

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!