Run simulink simulation in deployed app with from workspace block
Hi,
I am running Matlab 2023b. Now let me explain my situation:
I have an app that reads data with an external DLL. That works fine and the signals are stored in a variable called data.
The data variable looks like this:
In the model I use from workspace blocks like that:
After reading the data, I assign from the app to the base workspace so the simulink model can access it.
assignin(‘base’,’data’,app.data);
assignin(‘base’,’StopTime’,StopTime);
Afterwards I can run the simulation and provide the output to the app.
app.out = sim(‘LMDhDataCheck_Model’);
All of that works fine. Now to my problem. When I compile the app as standalone it does not read the input correctly.
I have tried already to precompile the model and then starting the exe, which does not work. It seems like the input is 0 all the time.
if isdeployed
% Code that gets run only by compiled applications
disp(‘Run deployed simulink sim’);
!LMDhDataCheck_Model;
load(‘LMDhDataCheck_Model.mat’);
vars = who();
TF = contains(vars, ‘rt_’);
varsFiltered = vars(TF);
for i = 1:length(varsFiltered)
app.out.(eraseBetween((varsFiltered{i,1}),1,3)) = eval((varsFiltered{i,1}));
end
else
% Code that gets run only in development environment
disp(‘Run development simulink sim’);
app.out = sim(‘LMDhDataCheck_Model’);
end
Then I tried to run the following code in the workspace before putting it in the app, but I get an error:
The tuned value of the variable ‘data’ (in the workspace ‘global-workspace’) has a different type than the variable’s default value.
in = Simulink.SimulationInput(‘LMDhDataCheck_Model’)
in = simulink.compiler.configureForDeployment(in)
in = setVariable(in, ‘data’, data)
in = setVariable(in, ‘StopTime’, StopTime)
out = sim(in)
Any help will be appriciated as I cannot find an answer in the forums.Hi,
I am running Matlab 2023b. Now let me explain my situation:
I have an app that reads data with an external DLL. That works fine and the signals are stored in a variable called data.
The data variable looks like this:
In the model I use from workspace blocks like that:
After reading the data, I assign from the app to the base workspace so the simulink model can access it.
assignin(‘base’,’data’,app.data);
assignin(‘base’,’StopTime’,StopTime);
Afterwards I can run the simulation and provide the output to the app.
app.out = sim(‘LMDhDataCheck_Model’);
All of that works fine. Now to my problem. When I compile the app as standalone it does not read the input correctly.
I have tried already to precompile the model and then starting the exe, which does not work. It seems like the input is 0 all the time.
if isdeployed
% Code that gets run only by compiled applications
disp(‘Run deployed simulink sim’);
!LMDhDataCheck_Model;
load(‘LMDhDataCheck_Model.mat’);
vars = who();
TF = contains(vars, ‘rt_’);
varsFiltered = vars(TF);
for i = 1:length(varsFiltered)
app.out.(eraseBetween((varsFiltered{i,1}),1,3)) = eval((varsFiltered{i,1}));
end
else
% Code that gets run only in development environment
disp(‘Run development simulink sim’);
app.out = sim(‘LMDhDataCheck_Model’);
end
Then I tried to run the following code in the workspace before putting it in the app, but I get an error:
The tuned value of the variable ‘data’ (in the workspace ‘global-workspace’) has a different type than the variable’s default value.
in = Simulink.SimulationInput(‘LMDhDataCheck_Model’)
in = simulink.compiler.configureForDeployment(in)
in = setVariable(in, ‘data’, data)
in = setVariable(in, ‘StopTime’, StopTime)
out = sim(in)
Any help will be appriciated as I cannot find an answer in the forums. Hi,
I am running Matlab 2023b. Now let me explain my situation:
I have an app that reads data with an external DLL. That works fine and the signals are stored in a variable called data.
The data variable looks like this:
In the model I use from workspace blocks like that:
After reading the data, I assign from the app to the base workspace so the simulink model can access it.
assignin(‘base’,’data’,app.data);
assignin(‘base’,’StopTime’,StopTime);
Afterwards I can run the simulation and provide the output to the app.
app.out = sim(‘LMDhDataCheck_Model’);
All of that works fine. Now to my problem. When I compile the app as standalone it does not read the input correctly.
I have tried already to precompile the model and then starting the exe, which does not work. It seems like the input is 0 all the time.
if isdeployed
% Code that gets run only by compiled applications
disp(‘Run deployed simulink sim’);
!LMDhDataCheck_Model;
load(‘LMDhDataCheck_Model.mat’);
vars = who();
TF = contains(vars, ‘rt_’);
varsFiltered = vars(TF);
for i = 1:length(varsFiltered)
app.out.(eraseBetween((varsFiltered{i,1}),1,3)) = eval((varsFiltered{i,1}));
end
else
% Code that gets run only in development environment
disp(‘Run development simulink sim’);
app.out = sim(‘LMDhDataCheck_Model’);
end
Then I tried to run the following code in the workspace before putting it in the app, but I get an error:
The tuned value of the variable ‘data’ (in the workspace ‘global-workspace’) has a different type than the variable’s default value.
in = Simulink.SimulationInput(‘LMDhDataCheck_Model’)
in = simulink.compiler.configureForDeployment(in)
in = setVariable(in, ‘data’, data)
in = setVariable(in, ‘StopTime’, StopTime)
out = sim(in)
Any help will be appriciated as I cannot find an answer in the forums. appdesigner, simulink, standalone MATLAB Answers — New Questions