convert matlab variables to simulink parameters

14 ビュー (過去 30 日間)
ByungHoon Lee
ByungHoon Lee 2018 年 5 月 24 日
コメント済み: Mert B. 2022 年 7 月 6 日
I have 700 matlab variables in my workspace. I want to convert all variables to simulink parameters. Do you know any easy way to convert the data? In my situation, I add parameters to workspace for convert all variables at once. it's really hard....
  2 件のコメント
TAB
TAB 2018 年 5 月 24 日
編集済み: TAB 2018 年 5 月 24 日
Do you mean, you want to convert simple workspace variable with Simulink.Parameter ?
ByungHoon Lee
ByungHoon Lee 2018 年 5 月 24 日
Yeah that right. Do you know that?. If I have no solution to convert the variable to Simulink.Parameter, I would make 700 Simulink.Parameters....

サインインしてコメントする。

採用された回答

TAB
TAB 2018 年 5 月 24 日
編集済み: TAB 2018 年 5 月 24 日
Write a script to collect the name, data type etc of all your workspace variable and make a loop to create Simulink.Parameter variables based on above info.
% Clear workspace
clear variables;
% Load variabled which are to be onverted in base workspace
% load here from m-file for mat-file or just create
param1 = 100;
param2 = 100;
% List of all workspace variables
wsVarList = whos;
for x=1:length(wsVarList)
% Collect variable name
varName = wsVarList(x).name;
% Save value. This variable will be replaced by Simulink.Parameter
varVal = eval(varName);
% Create parameter with same name as variable name and assign value
eval([varName ' = Simulink.Parameter']);
eval([varName '.Value = ' num2str(varVal)]);
% Based on your requirement, you can assign other properties
% wsVarList(x).class
% wsVarList(x).size
end
  1 件のコメント
Sina Ehtejab
Sina Ehtejab 2020 年 5 月 18 日
You got a big brain and bigger than your brain is your generous heart . Have a nice day sir

サインインしてコメントする。

その他の回答 (1 件)

ByungHoon Lee
ByungHoon Lee 2018 年 5 月 24 日
Thank you so much. I will do that. And i will give a feedback to you.
  1 件のコメント
Mert B.
Mert B. 2022 年 7 月 6 日
How we can consider variables in matrix form ?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLarge Files and Big Data についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by