How do i write to the base workspace in simulink?
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I currently have:
BatteryParams = struct();
for idx = 1:numCells
%%Lookup Table Breakpoints
BatteryParams(idx).SOC_LUT = [0 0.1 0.25 0.5 0.75 0.9 1]';
BatteryParams(idx).Temperature_LUT = [5 20 40] + 273.15;
%%Em Branch Properties (OCV, Capacity)
% Battery capacity
BatteryParams(idx).Capacity_LUT = [
80.0000 79.5000 79.0000]; %Ampere*hours
From my GUI i want to change the "BatteryParams(idx).Capacity_LUT" in the workspace while running the simulation.
I have gotten a hint to these functions but otherwise I am unsure of how to proceed.
command = sprintf('BatteryParams(%d).Capacity_LUT = %f;', idx, value)
evalin('base', command);
I am guessing I have to use the "to workspace" block in simulink but other than what i have written here now i am kinda blank on the sollution to my problem.
Can anyone help me out ?
2 Kommentare
Ajay Kumar P
am 28 Apr. 2015
Please try using assignin('base','varibale name',value) function to create/update variable values in the base workspace.
Stephen23
am 28 Apr. 2015
Although global and assignin will work, they are also very difficult to debug and make code-checking almost impossible. It is reccomended to pass values as much as possible, which means they should be collected and passed as output arguments.
This page has more information on this topic:
Antworten (1)
Navaneeth Raman
am 22 Apr. 2015
Hello,
Can you be clear on how you have your model setup and how the above code ties in within your system? Its not clear where your code fits in.
Thanks, Navaneeth
1 Kommentar
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!