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

3 次查看(过去 30 天)
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.

采纳的回答

Walter Roberson
Walter Roberson 2020-12-1
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 个评论
Walter Roberson
Walter Roberson 2020-12-2
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

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics Object Programming 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by