Changing a string in a matrix to a variable with a value given in another matrix.
3 views (last 30 days)
Show older comments
Its pretty simple what i want to do but seems complex on matlab. For example we have two difference types of arrays
if true
% code
Names = {'AB','GH','BC';'BG','FG','CF';'DE','CD','EF'}
Values = [1 2 5;1 4 5;1 5 6]
end
all I need to do is take the Value from the String array and make a variable out of it and then give that variable a value from the Values matrix in the corresponding spot.
0 Comments
Accepted Answer
James Tursa
on 6 Oct 2016
Edited: James Tursa
on 6 Oct 2016
Well, you can do this using the eval() function, but it is generally not a good idea to do so. You are popping these variables into the workspace dynamically. How do you expect to deal with them downstream in your code? With more eval() statements? Ugly and difficult to maintain. See this link for alternatives:
E.g.,
eval([Names{2,3} '=' num2str(Values(2,3))])
Do you really want to do stuff like this everywhere in your code when you want to use the variable? Probably not.
0 Comments
More Answers (0)
See Also
Categories
Find more on Characters and Strings in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!