A way to incorporate the name of one vairable into another?
1 view (last 30 days)
Show older comments
I have 5 arrays, A1, A2, A3, B, and C. I have an algorithm that finds matches between values in the A arrays and the B and C arrays then collects them in a matrix "match_results". Is there a way to incorporate the name of the A array into the match_results name? That is have the code output "match_results_A1", etc, after running?
Another way of asking: Say I have arrays A, B C, D and E. I want my code to compare A to D and E, then output a match_results matrix, then compare B to D and E and output a second match matrix, then the same for C. Ideally, I would end up with three matrices labeled "match_A" "match_B" and "match_C". Is there a way to do this, or am I just going to get multiple instances of "DON'T DO THIS! http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F"?
0 Comments
Answers (1)
Image Analyst
on 3 Jun 2014
To me, that seems like a very bad idea , something along the lines of http://matlab.wikia.com/wiki/FAQ#How_can_I_create_variables_A1.2C_A2.2C....2CA10_in_a_loop.3F
7 Comments
Image Analyst
on 4 Jun 2014
One way to do it is to use dynamic structure names. I don't like them but they are supported and are the preferred way, much more so that what you've asked to do. See http://www.mathworks.com/matlabcentral/answers/94573-how-can-i-dynamically-extract-fields-from-a-structure-and-create-variables-in-the-matlab-workspace-u
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!