How can I export cell to double variable
显示 更早的评论

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 ....
回答(2 个)
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
2018-8-18
编辑:turker dirlik
2018-8-18
this is what I looking for. Thank you so much Adam
Stephen23
2018-7-26
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
类别
在 帮助中心 和 File Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!