How to manage a list of variables with parameters?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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.
0 comentarios
Respuesta aceptada
Daniel Shub
el 6 de Oct. de 2011
This seems to be what classes are perfect for.
classdef students
properties
Grades;
Absences;
...
Más respuestas (3)
Sean de Wolski
el 6 de Oct. de 2011
I would use a struct
Students = struct('Grades',{'A';'B'},'Absences',[4;11])
etc.
doc struct
for more info
0 comentarios
Laura Proctor
el 6 de Oct. de 2011
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
el 6 de Oct. de 2011
use dataset() or structure
Student=cell2struct(repmat({[]},3,1),{'Grades','Absense','Age'},1)
StudentProperty=fieldnames(Student)
0 comentarios
Ver también
Categorías
Más información sobre Structures en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!