How to copy/paste or use script to modify array in Variable Editor?

조회 수: 3 (최근 30일)
Mark
Mark 2024년 1월 10일
편집: Walter Roberson 2024년 1월 11일
I want to modify a 12x15 array in one of the Simulink reference applications. So far, the only way I can access it seems to be through the Variable Editor. (Open Model Explorer, go to Simulink Root -> FCElectricPlant -> Model Workspace, open Mot in Variable editor, and then browse to "efficiency_table")
Is there a way to copy/paste data in this table within Variable Editor?
Or is there an alternate way to get to this data where I can make modifications?
Thanks!

채택된 답변

Harimurali
Harimurali 2024년 1월 11일
편집: Walter Roberson 2024년 1월 11일
Hi Mark,
The variables in the model workspace can be accessed and modified using the "Simulink.ModelWorkspace" object of the model in MATLAB. Here is an example MATLAB code to do the same:
% Load the model into memory if it is not already loaded
load_system('FCElectricPlant');
% Get the variable from the model workspace
hws = get_param('FCElectricPlant', 'ModelWorkspace');
efficiency_table = hws.getVariable('efficiency_table');
% Now you can modify the efficiency_table as needed
% For example, to change the value at row 5, column 6:
efficiency_table(5, 6) = newValue;
% After modifying the efficiency_table, write it back to the model workspace
hws.assignin('efficiency_table', efficiency_table);
% Save changes to the model if necessary
save_system('FCElectricPlant');
For more information on how to interact with the model workspace using a "Simulink.ModelWorkspace" object: https://www.mathworks.com/help/releases/R2023b/simulink/slref/simulink.modelworkspace.html

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programmatic Model Editing에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by