Simulink Unable to Identify Variable in Base Workspace

I am running a program which calls Simulink, however when simulink gets called I get this error:
Error using Run_Sim (line 39)
Error evaluating expression 'Tsim' for 'StopTime' specified in the Configuration
Parameters dialog for block diagram 'New_model_working_plecs_2012b': Undefined function or
variable 'Tsim'.
however, Tsim is in the base workspace so im not sure what is going wrong here, this file also runs fine matlab 2012

回答 (2 件)

Sebastian Castro
Sebastian Castro 2016 年 6 月 2 日

0 投票

Are you calling the command from inside a MATLAB function?
If so, you need to make sure to tell the sim command to use the current caller's (the function's) workspace.
simout = sim('modelName','SrcWorkspace','current', ... )
- Sebastian

4 件のコメント

Jake G
Jake G 2016 年 6 月 2 日
I am but the variables I need are in the base workspace.
Error using Run_Sim (line 39)
Undefined function or variable 'N_samples'.
and after I run 'Main' I can look over into the workspace and see:
'N_samples 600'
really not to sure whats going on here because like I said this code will run in 2012(I need it to run in this version)
Sebastian Castro
Sebastian Castro 2016 年 6 月 2 日
Oh, so you want to use the base workspace inside the function.
Would 'SrcWorkspace','base' do it for you?
- Sebastian
Jake G
Jake G 2016 年 6 月 2 日
I am starting to think my error is more involved than this, I am running matlabs Genetic Algorithm using simulink as the fitness function and that is where my problem is coming from
Jake G
Jake G 2016 年 6 月 3 日
I figured out the problem, Thanks for your help!

サインインしてコメントする。

Arihant Sureka
Arihant Sureka 2018 年 9 月 19 日
編集済み: Sebastian Castro 2018 年 9 月 19 日

0 投票

Hi Sebastian
The Version is Matlab 2017b and still the Problem persists. I have already defined my model properties in the base Workspace but Simulink is not able to capture it. Also, this command line
simOut = parsim(simIn,'SrcWorkspace','current');
gives an error
'Invalid parameter 'SrcWorkspace' specified'.
Please guide further as there isn#t any answer available anywhere.
Thanks

2 件のコメント

Sebastian Castro
Sebastian Castro 2018 年 9 月 19 日
Your question is on parsim and not sim, which are different functions. As the error message suggests, parsim does not have a SrcWorkspace property to configure.
Looking at the documentation, and depending on how your data is set up, you either want to use AttachedFiles or TransferBaseWorkspaceVariables.
- Sebastian
Arihant Sureka
Arihant Sureka 2018 年 9 月 21 日
Hi Sebastien
The thing worked. Thanks for the help but since the Matlab 2017b has Bugs I had to clear the previously created slprj Folder and stuff.
Thanks and cheers!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSimulink Functions についてさらに検索

製品

タグ

質問済み:

2016 年 6 月 1 日

コメント済み:

2018 年 9 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by