Extracting Matrix Elements using Defined Variable in Workspace
3 views (last 30 days)
Show older comments
Hello,
I'm trying to figure out if there is a way to identify a matrix element by passing through a variable string name inside the matrix call out as shown below:
System_Type= 2 <--- Variable Defined in Workspace
OutputMatrix = [8x8] <--- Matrix Defined in Workspace
OutputMatrix(1,1) <--- Normally Defining the value of the element in matrix
OutputMatrix('System_Type', 1) <--- How I would like to pass through variable "System_Type" and be able to extract the element of the matrix based on the string input value.
I'd appreciate it if anyone can provide guidance on this! Thanks Nima
0 Comments
Accepted Answer
Walter Roberson
on 8 Jun 2012
No, or at least not with that syntax. You can use OutputMatrix(System_Type, 1)
If it is important that you pass the column name to another routine, then one way would be to pass it as an additional argument that you just use for whatever output purpose you need. Another way would be to construct a structure such as
colnames.ID_number = 1;
colnames.System_Type = 2;
colnames.Revision_Date = 3;
and then when you need to convert the field name to a value,
FieldName = 'System_Type';
[...]
OutputMatrix( colnames.(FieldName), 1)
More Answers (0)
See Also
Categories
Find more on Subplots 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!