How do i write to the base workspace in simulink?
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
Ajay Kumar P
2015-4-28
Please try using assignin('base','varibale name',value) function to create/update variable values in the base workspace.
Stephen23
2015-4-28
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:
回答(1 个)
Navaneeth Raman
2015-4-22
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
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!