How to populate a n-d lookup table from the workspace in R2011b?

1 次查看(过去 30 天)
If I enter the values directly in the n-d lookup block, it works, but if I enter parameter names in the lookup block I get "Undefined function or variable " ", but I know it IS defined and present in the workspace.

回答(1 个)

Arnab Sen
Arnab Sen 2015-12-31
I understand that you would like to put some variables in 'Table data' parameter of 'n-D Lookup Table' block and simulate the model, but you observe error 'undefined variable or function' while trying to do so.
This issue may occur if the variables is not in the workspace of the model as the model can access only the variables from its own workspace.
You can use in-built 'assignin' function to set a variable in a particular workspace. You may execute the following code snippet in MATLAB command Window for demonstration purpose:
% Suppose the name of the model under consideration is 'sampleModel' and the variable name is 'a':
>> hws = get_param('sampleModel','modelworkspace')
>> assignin(hws,'a',5);
Now, set the 'Table Data' parameter if 'n-D Lookup Table' as 'reshape(repmat([4 a 6;16 19 20;10 18 23],1,2),[3,3,2])' and simulate the model.
For more details about the functions 'assignin' and 'get_param', refer to the following links:

类别

Help CenterFile Exchange 中查找有关 Lookup Tables 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by