adding property dynamically in the class
Show older comments
I have a class,
classdef data < dynamicprops
properties
result1 = []
result2 = []
end
end
Now I need to add dynamically many properites to the class. For example
reult 3, result 4, result 5 etc
I tried using data.('result3') = [] like how we add a field in the strcture. But i am getting the error.
how can i do this?
Thanks a lot
2 Comments
Adam
on 23 Feb 2017
Why wouldn't you just use a single property
results
as an array of results that you can index into?
Stephen23
on 23 Feb 2017
@Gopalakrishnan venkatesan: as Adam already said, using an array (possible cell array) would be a much better solution. You should really consider using the simpler solution rather than making this complicated with dynamic properties.
Accepted Answer
More Answers (1)
doc dynamicprops
gives details on the addprops function which I would assume you need to use. I have never wanted to do any dynamic properties on my own classes as it seems a bit of a suspicious design premise, but how did you manage to come across knowing you need to use dynamicprops yet not find addprops?!
2 Comments
Gopalakrishnan venkatesan
on 23 Feb 2017
Arun Aiyer
on 16 Jul 2022
If you want to use inspect function to create a dynamic settings table related to hardware for example.
The inspect function creates a dynamic interface for the object handle properties, which needs to be changed. The function that creates the dynamic props is to generate these settings objects.
Categories
Find more on Argument Definitions in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!