data structure in Matlab for actively add and remove objects or structure.
9 次查看(过去 30 天)
显示 更早的评论
Hi!
I need to actively add and remove objects or structures that have multiple pieces of information, including a handle that controls UIAxes.
Does MATLAB have such a data structure?
For example, it feels like a binary tree or a character that can be mass produced in a game.
ADD
I'm making a 3D graphical GUI that represents the orbit of a satellite over time. The number of satellites can be multiple, and each has different properties (orbital element, satellite mass, etc.), so I compared it to a character in a game. Since the shape of the orbit that should appear in UIAxes is different depending on the orbital element of the satellite, I thought that the object/structure should also contain the handle of the UIAxes. This GUI should be able to create and remove satellites, which is why I asked the above question.
2 个评论
Geoff Hayes
2022-6-15
@Jae-Hee Park - can you provide more details on what you are attempting to do? Is the game an example or something like what you are attempting? How do the objects/structures relate to the handle to the UIAxes?
回答(1 个)
Karan Singh
2023-10-4
编辑:Karan Singh
2023-10-4
Hi Jae-Hee,
From what I understand, the goal is to manage multiple objects or structures with multiple pieces of information, including handles to control UI elements like “UIAxes” in MATLAB.
You can use a cell array or a structure array:
- Cell Array: A cell array is a versatile data structure that can hold elements of different types. Each cell can store a different object or structure with its associated properties. You can dynamically add or remove elements from the cell array using indexing or cell array functions.
For example, you can create a cell array to store satellite objects or structures, where each cell contains the necessary information, including the handle to the UIAxes:
satellites = {}; % Initialize an empty cell array
% Add a satellite object/structure with its properties
satellite1 = struct('name', 'Satellite 1', 'orbitalElement', [1 2 3]);
satellite1.UIAxesHandle = uiaxes; % Assign the handle to UIAxes
satellites{end+1} = satellite1; % Add the satellite to the cell array
% Remove a satellite
satellites{1} = []; % Remove the satellite at index 1
satellites = satellites(~cellfun('isempty', satellites)); % Remove empty cells
- Structure Array: A structure array is another option to store multiple objects or structures with different properties. Each structure in the array can represent an individual satellite with its associated properties, including the handle to the UIAxes.
satellites = struct([]); % Initialize an empty structure array
% Add a satellite object/structure with its properties
satellite1 = struct('name', 'Satellite 1', 'orbitalElement', [1 2 3]);
satellite1.UIAxesHandle = uiaxes; % Assign the handle to UIAxes
% Add the satellite to the structure array
satellites = [satellites satellite1];
% Remove a satellite
satellites(1) = []; % Remove the satellite at index 1
Both approaches allow you to add and remove objects or structures dynamically. You can access and manipulate the properties of each object/structure, including the handle to the UIAxes.
Attached below are some documentation links that you may find helpful:
Hope this helps!
Karan Singh Khati
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Satellite Mission Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!