Construct a reference to a matrix where the matrix name is the value of a variable
Show older comments
I want to construct a matrix reference from information contained in a set of variables. Example: say I want to set a matrix with these values:
fData = saaData(:, 16)
However, the statement is part of a for loop, and both the column and the particular matrix being referenced change on each pass. They are specified by a pair of variables:
fctSource = factors{i, 2};
fctIdx = factors{i, 3};
where on this pass, factors{i, 2} = saaData and factors{i, 3} = 16.
How can I construct a command, using fctSource and fctIdx, that will return the column vector given by saaData(:, 16)?
Accepted Answer
More Answers (1)
Walter Roberson
on 9 Apr 2013
0 votes
2 Comments
William
on 9 Apr 2013
Walter Roberson
on 9 Apr 2013
The techniques for creating a set of variables are closely related to the techniques for using a set of variables.
And you missed the big point of the beginning: DON'T DO THAT! Store your variables in indexable forms instead of using different variable names.
Categories
Find more on Matrix Indexing 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!