Variable assignment in workspace
1 次查看(过去 30 天)
显示 更早的评论
a=[1,2,3,4,5,6]
b=['c','d','e','f','g','h']
how can i assign the values to the variables that are present in array b and the values of those present in array a without hard coding the variable names.
3 个评论
Walter Roberson
2021-8-16
Why do you want to do that?
What would you do if the Excel file happened to name a variable that was the same as one of the variable names you were using to code the function?
... If you were to store everything into a struct like I demonstrated, then you would not have any conflicts.
回答(1 个)
Walter Roberson
2021-8-16
The best approach is do not do that
For example, instead
a = [1,2,3,4,5,6]
b = {'c','d','e','f','g','h'}
output = cell2struct(num2cell(a), b, 2)
2 个评论
Walter Roberson
2021-8-16
The best approach is do not do that
If you are not effectively extending the syntax of MATLAB like syms or IBM's cvx, then what you are asking for is more trouble than it is worth, in the long run.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!