I have parameter list and their values in 13x2 cell. First coloum is variable name , second is variable value. (you can see screenshot attechment) How can export variable names with their values in double as;
Cd=5 Cw=3.888 Hp=0.2 ....

3 件のコメント

Paolo
Paolo 2018 年 7 月 23 日
Not sure I follow, do you want to combine two cell arrays? Perhaps the screenshot could clarify.
Adam Danz
Adam Danz 2018 年 7 月 25 日
Have you tried my solution below?
Stephen23
Stephen23 2018 年 7 月 26 日
Read this to know why it is not recommended to dynamically create or access variables names:

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

回答 (2 件)

Adam Danz
Adam Danz 2018 年 7 月 23 日
編集済み: Adam Danz 2018 年 7 月 23 日

1 投票

Creating dynamic variable names is often looked down upon . Please read those warning and consider alternatives.
That being said, here's what I think you're looking for.
data = {
'var1', 123;
'var2', sqrt(42);
'var3', pi;
};
for i = 1:length(data)
assignin('caller', data{i,1}, data{i,2});
end

2 件のコメント

turker dirlik
turker dirlik 2018 年 8 月 18 日
編集済み: turker dirlik 2018 年 8 月 18 日
this is what I looking for. Thank you so much Adam
Adam Danz
Adam Danz 2018 年 8 月 18 日
編集済み: Adam Danz 2020 年 2 月 25 日
I'm glad this helped!

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

Stephen23
Stephen23 2018 年 7 月 26 日

1 投票

Rather than magically creating the variables, a simple and efficient alternative is to create a structure from that cell array:
C = parameter.';
S = struct(C{:});
and then you can simply access the fields of that structure:
S.Cd
S.Cw
S.Hp
... etc

カテゴリ

質問済み:

2018 年 7 月 23 日

編集済み:

2020 年 2 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by