Extracting Matrix Elements using Defined Variable in Workspace

조회 수: 3 (최근 30일)
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

채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 8일
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)
  댓글 수: 1
Nima Forghani
Nima Forghani 2012년 6월 14일
Thanks you Walter for your response!
This workaround helps.
thanks again!
Nima

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Subplots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by