Extracting Matrix Elements using Defined Variable in Workspace

5 visualizzazioni (ultimi 30 giorni)
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

Risposta accettata

Walter Roberson
Walter Roberson il 8 Giu 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)

Più risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by