Creation of multiple objects in same class
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
VIJAYKUMAR KAMBLE
el 27 de Abr. de 2021
Comentada: VIJAYKUMAR KAMBLE
el 27 de Abr. de 2021
If any class is defined then how I can create different objects of the same class. Answers with suiable examples are appreciated. Thanks
0 comentarios
Respuesta aceptada
Steven Lord
el 27 de Abr. de 2021
It depends. Is that class a handle class or a value class? If value, just call the constructor or do whatever you need to instantiate an instance. In this example A and B are both table arrays but modifying one doesn't modify the other. Even after I change one of the elements of B the corresponding element of A is unchanged.
A = array2table(magic(4))
B = A;
B{2, 'Var3'} = NaN
A
3 comentarios
Steven Lord
el 27 de Abr. de 2021
If you're asking if you can create variables named CLM_60_RP, CLM_80_RP, etc. you can do this but you shouldn't.
I'd make a struct array or a table array to contain your objects instead.
pins.CLM_60_RP = 42 % Using a hard-coded field name
pinname = 'CLM_80_RP';
pins.(pinname) = -99 % Using a dynamic field name
y = pins.CLM_60_RP % Retrieve data the same way
z = pins.(pinname)
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical 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!

