Calling variables instead of values
Show older comments
I had previously asked this: http://www.mathworks.com/matlabcentral/answers/19875-calling-variables-instead-of-values And marked as answered, but I have a little hiccup.
I have this:
A=6; B=7; C=5;
x = [7 5 6]
I want to call x1 as:
x1 =
B C A
Previous answered:
x = [2 3 1]
xc = {'A' 'B' 'C'}
x1 = xc(x)
This line of code only works for values that are within the number of columns of the matrix.
Accepted Answer
More Answers (1)
Alex
on 31 Oct 2011
0 votes
My original comment about one-to-one, I realize, is not the best descriptor.
I've since edited the original post to reflect that and I'll try to explain the differences a little better.
In your original question, you have a base set (x) and you are looking to match values within that set. Since all the values are contained within a single set, this is easy.
In the new question, there are multiple sets (A, B, & C) that all have to be searched since each one could possibly contain the solution that you desire.
If there is a way to combine the multiple sets (like Will's above comment) into a single set (set S in Will's example), then the solution can be achieved much easier. Otherwise, the if/else tree or the switch/case ideas I mentioned are the best options, that I know of.
Categories
Find more on MATLAB in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!