Simulink Mask Editor - Lock parameter access with password

13 Ansichten (letzte 30 Tage)
Lars Lindner
Lars Lindner am 9 Apr. 2022
Beantwortet: Lars Lindner am 15 Nov. 2024 um 10:52
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

Antworten (2)

Ayush
Ayush am 31 Jul. 2024
Bearbeitet: Ayush am 31 Jul. 2024
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!

Lars Lindner
Lars Lindner am 15 Nov. 2024 um 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

Kategorien

Mehr zu Interactive Model Editing finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by