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!