AppDesigner: Plotting Simulink Model's Result
5 ビュー (過去 30 日間)
古いコメントを表示
Trying to make a standalone app. Im having to issues:
1-Plotting the SImulation's Result.
Ive seen multiple documentation/questions related to this Topic but for some reason i still dont know how to achieve it :(. I have managed to be able to plot the simulation's results, but the app works only as a GUI and not will be able to deploy. I believe this is related to the code related to the plotting. What i did was to save the results in Workspace and then retrieve thier values. Please refer to line 75 to 80. How can i do it? I ve seen it could be done using Ports. I tried following the documentations/questions but no luck. A snapshot of the model is seen below.
---------------------------------------------------------------------------------------------------------
2-The values assigned to the variables don't get updated
Not all variables get updated in the model. I've tried using the setVariable which is used when deploying an app and also the assignin but both didnt change the desired values. I've noticed that the variables which are inside an SPS block don't get changed, only the ones in Simulink blocks. The code is found below.
Modelname = 'Habal';
simInp = Simulink.SimulationInput(Modelname);
simInp = simInp.setVariable('hrg',app.HRGWidOhmEditField.Value);
simInp = simInp.setVariable('tr',app.AnstiegzeitsEditField.Value);
simInp = simInp.setVariable('hp',app.LeistungHPEditField.Value);
simInp = simInp.setVariable('ls',app.StreuinduktivittHEditField.Value);
simInp = simInp.setVariable('re',app.EisenverlustOhmEditField.Value);
simInp = simInp.setVariable('l',app.LngemEditField.Value);
simInp = simInp.setVariable('lc',app.InduktivittsbelagHmEditField.Value);
simInp = simInp.setVariable('rc',app.WiderstandsbelagOhmmEditField.Value);
simInp = simInp.setVariable('cc',app.AderAderKapazittsbelagFmEditField.Value);
simInp = simInp.setVariable('sc',app.AderSchirmKapazittsbelagFmEditField.Value);
% assignin('base','hrg',app.HRGWidOhmEditField.Value);
% assignin('base','tr',app.AnstiegzeitsEditField.Value);
% assignin('base','hp',app.LeistungHPEditField.Value);
% assignin('base','ls',app.StreuinduktivittHEditField.Value);
% assignin('base','re',app.EisenverlustOhmEditField.Value);
% assignin('base','l',app.LngemEditField.Value);
% assignin('base','lc',app.InduktivittsbelagHmEditField.Value);
% assignin('base','rc',app.WiderstandsbelagOhmmEditField.Value);
% assignin('base','cc',app.AderAderKapazittsbelagFmEditField.Value);
% assignin('base','sc',app.AderSchirmKapazittsbelagFmEditField.Value);
StopTime = num2str(app.SimZeitsEditField.Value);
simInp = simInp.setModelParameter('StopTime', StopTime);
% configure simInp for deployment
simInp = simulink.compiler.configureForDeployment(simInp);
simOut = sim(simInp);
time = simOut.tout;
vpp = simOut.vpp.signals.values;
vpg = simOut.vpg.signals.values;
0 件のコメント
回答 (2 件)
Anurag
2023 年 8 月 8 日
Hello!
The problem with not being able to generate a standalone app is due to "What i did was to save the results in Workspace and then retrieve thier values."
To generate a standalone app you cannot use the workspace for performing your calculations.
Brahmadev
2023 年 8 月 31 日
編集済み: Brahmadev
2023 年 8 月 31 日
Hi Ahmed,
I understand that you are trying to edit the parameters of a Simscape model through an App’s Edit Fields.
You can use the “set_param” function to set the value of parameters in your Model through the CallBack function of the respective EditFields. Here is an example for reference.
% Value changed function: EditField
function EditFieldCallbackFn(app, event)
value = app.HRGWidOhmEditField.Value;
h = load_system(Modelname);
% Here hrg is the parameter name like you have used in your example
% and the value should be converted to appropriate datatype as expected by the block parameter
set_param('Habal/BlockName', 'hrg', string(value));
% Similarly you can get parameter values using the get_param function
get_param('Habal/BlockName','hrg');
end
Make sure to load the model before trying to edit the parameters. Also use the Programmatic name for the block parameters. This can be checked by right-clicking on the parameter and clicking “What’s This?”
You can refer the MathWorks documentation for “set_param” through the link below.
Hope this helps!
2 件のコメント
Brahmadev
2023 年 9 月 4 日
Hi Ahmed,
Thanks for letting me know. Here are some more things to consider. The configurability should be set to "run-time" for all the parameters you are trying to change dynamically. Also, variables of the same name should not exist in the base workspace as they will take precedence for the Model Parameters and the updated values from the App will not be reflected.
You can check out the Examples below for more information on deploying using "Simulink Compiler":
- https://in.mathworks.com/help/slcompiler/ug/deploy-a-simulation-with-simulink-compiler.html
- https://in.mathworks.com/help/slcompiler/ug/deploy-from-matlab-command-line.html
Hope this helps!
参考
カテゴリ
Help Center および File Exchange で Deploy Standalone Applications についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!