How to manage a list of variables with parameters?

조회 수: 2 (최근 30일)
K E
K E 2011년 10월 6일
I need to keep track of a list of variables and their parameters, for example one variable might be 'Students' and the parameters might be 'Grades', 'Absences', and 'Age' . Another variable might be 'Teachers' and the parameters might be 'Salary' and 'Classes'. What is the best way to keep track of these strings? Create a cell array? I do not need to assign values at the present, I just want to keep track of which parameters go with which variables.

채택된 답변

Daniel Shub
Daniel Shub 2011년 10월 6일
This seems to be what classes are perfect for.
classdef students
properties
Grades;
Absences;
...
  댓글 수: 1
K E
K E 2012년 3월 14일
Thanks so much. Had never even heard of them.

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

추가 답변 (3개)

Sean de Wolski
Sean de Wolski 2011년 10월 6일
I would use a struct
Students = struct('Grades',{'A';'B'},'Absences',[4;11])
etc.
doc struct
for more info

Laura Proctor
Laura Proctor 2011년 10월 6일
You may want to check out structures or datasets.
Here is a blog article that goes into a little more detail.
If you use a structure, for example, you would have the variable named Students, and the fields would be Grades, Absences and Age. If you wanted to recall all the fields, just use the fieldnames function.
Both are very useful, and I think they will work for what you want. If you wanted to get more fancy, you could create your own class objects with the parameters as properties.

Fangjun Jiang
Fangjun Jiang 2011년 10월 6일
use dataset() or structure
Student=cell2struct(repmat({[]},3,1),{'Grades','Absense','Age'},1)
StudentProperty=fieldnames(Student)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by