How to fix the problem of fetching the simulink block from the customized library in the matlab app designer using matlab app designer code?

2 次查看(过去 30 天)
Here, we are running all the codes shown below in the matlab app designer.
Initialy, we have taken a simulink block from the existing matlab library using this code, and it run successfully.
open_system(new_system('myModel'));
add_block('simulink/Commonly Used Blocks/Constant','myModel/Constant');
set_param('myModel/Constant','position',[140,80,180,120]);
But, on applying the same code to select the simulink block from our customized library, it shows the following error.
open_system(new_system('myModel'));
add_block('simulink/mylib/Constant','myModel/Constant');
set_param('myModel/Constant','position',[220,80,260,120]);
So, the command window in matlab shows following error message.
Error using app2/MylibraryButtonPushed
There is no block named 'simulink/mylib/Constant'
Error in matlab.apps.AppBase>@(source,event)executeCallback(ams,app,callback,requiresEventData,event) (line 62)
newCallback = @(source, event)executeCallback(ams, ... - Show complete stack trace
Error while evaluating Button PrivateButtonPushedFcn.

回答(1 个)

Fangjun Jiang
Fangjun Jiang 2023-12-9
It is because your customized library is not set up as "simulink/mylib". It is unlikely you can add your library to underneath "simulink".
Anyway, open your customized library manually, select a block, go to MATLAB Command Window, run "gcb", you will get the fullpath of that block. Use that fullpath as the SourceBlock in add_block(SourceBlock, destination).

类别

Help CenterFile Exchange 中查找有关 Simulink Functions 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by