Azzera filtri
Azzera filtri

data structure in Matlab for actively add and remove objects or structure.

3 visualizzazioni (ultimi 30 giorni)
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 Commenti
Geoff Hayes
Geoff Hayes il 15 Giu 2022
@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?
Jae-Hee Park
Jae-Hee Park il 15 Giu 2022
Modificato: Jae-Hee Park il 15 Giu 2022
@Geoff Hayes Actually, 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.

Accedi per commentare.

Risposte (1)

Karan Singh
Karan Singh il 4 Ott 2023
Modificato: Karan Singh il 4 Ott 2023
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

Categorie

Scopri di più su Satellite and Orbital Mechanics in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by