Is it possible to define the properties for a class using cell array?

7 vues (au cours des 30 derniers jours)
J. Hu
J. Hu le 8 Oct 2013
Commenté : J. Hu le 9 Oct 2013
For example, I have a cell array AA={'x' 'y' 'z'} obtained by reading external files such as Excel table. How can I define the properties x, y, z for a class by referring to AA or a function with output AA. Is this possible?
instead of:
classdef T
properties
x
y
z
end
end
I want something like:
classdef T
properties
AA's elements
end
end
Thanks...
  1 commentaire
J. Hu
J. Hu le 9 Oct 2013
Seems it is not possible? Matlab may consider adding this function.

Connectez-vous pour commenter.

Réponse acceptée

Sean de Wolski
Sean de Wolski le 9 Oct 2013
Modifié(e) : Sean de Wolski le 9 Oct 2013
Ycan have your class inherit from DynamicProps and this will allow you to add properties dynamically.
C = {'x','y','z'};
D = exampleDynProp; %attached
for ii = 1:numel(C);addprop(D,C{ii});end
D

Plus de réponses (0)

Catégories

En savoir plus sur Data Type Identification dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by