Is there a way to store original structs in a cell array?

1 view (last 30 days)
Hello, I am trying to design an application and I want to change "Enable" property of some spinners according to user input. However, I have 30 spinners in my app and I do not want to write if or switch conditions for every possible input, so I considered storing spinners in a cell array by writing get(app.Spinner). It did not work because (I think- I am new to programming) a copy of the object is assigned into cell array. Therefore, I am asking this if storing an original object is available or is there any different approach that I can achieve my goal. Any help appreciated.

Accepted Answer

Walter Roberson
Walter Roberson on 1 Dec 2020
When you ask to get(app.Spinner) you are asking for the public properties of app.Spinner to be fetched. Most object properties are not handle objects, so you mostly get data such as 'on' or coordinate vectors.
Properties that happen to be handle objects will have the handle being saved. MATLAB is not deliberately making copies of the contents of handle objects.
If you want to locate graphic objects with a particular property, use findobj()
  3 Comments
Walter Roberson
Walter Roberson on 2 Dec 2020
findobj locates objects and returns handles to them. You can then query their properties.
get() fetches properties but has to be told where it is fetching from.
figs = findobj(groot, 'type', 'figure')
%figs is just handles
n = get(figs, 'name')
%n will now be a cell array of figure names
%unless only one figure was found. Then
%n would be the figure name directly

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Identification 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!