Simulink Mask Editor - Lock parameter access with password
14 次查看(过去 30 天)
显示 更早的评论
Hello everybody, I hope you are fine and have good wealth.
I am using the mask editor to create costum libraries and would like to lock the access to some parameters with a password, so that the user can have some kind of "admin" access to some parameters using this password. Is this possible and if yes, which approach can you recommend?
Thanks everybody for your valuable help and with best wishes,
Lars
0 个评论
回答(2 个)
Ayush
2024-7-31
编辑:Ayush
2024-7-31
Hello Lars,
Yes, it is possible to create password-protected access to certain parameters in Simulink using the Mask Editor by creating a custom script that introduces protected parameters with their intial visibility turned off and can be accessed once the condition is set to true, in your case when the admin inputs the password. You can utilize the following example code for your reference:
% Create the Password Field
addParameter(maskObj, 'admin_password', 'Type', 'edit', 'Prompt', 'Enter Admin Password');
% Create the Protected Parameters
addParameter(maskObj, 'protected_param1', 'Type', 'edit', 'Prompt', 'Protected Parameter 1', 'Visible', 'off');
addParameter(maskObj, 'protected_param2', 'Type', 'edit', 'Prompt', 'Protected Parameter 2', 'Visible', 'off');
% Add the Callback Script
maskObj.Parameters(admin_password).Callback = @checkPassword;
function checkPassword
blk = gcb;
enteredPassword = get_param(blk, 'admin_password');
correctPassword = 'your_secure_password';
% Condition to check if the entered password matches the correct password
if strcmp(enteredPassword, correctPassword)
% Toggle Visibility 'On'
set_param(blk, 'protected_param1', 'Visible', 'on');
set_param(blk, 'protected_param2', 'Visible', 'on');
else
% Toggle Visibility 'Off'
set_param(blk, 'protected_param1', 'Visible', 'off');
set_param(blk, 'protected_param2', 'Visible', 'off');
end
end
Hope this helps you!
0 个评论
Lars Lindner
2024-11-15,10:52
He Ayush, thank you very much for your answer.
I am actually using Matlab R2022a and would like to ask, where this code must be executed? Should it be defined in the Code tab of the mask editor (Initialization oder Parameter callback section?) or does it need to be executed as an additional script
How do I define the "maskObj" variable?
Thanks Ayush for your valuable help and with best wishes,
Lars
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Interactive Model Editing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!