Structure that contain an array of points with string names and coordinates
Afficher commentaires plus anciens
Hello,
I need to create and dynamically fill a structure that describes a point in space and which contains IDs (integers), coordinates [X, Y, Z] of type double and a name (string) label of each point. Labels can vary in length. Later I want to access and display all elements in the structure which corresponds to a certain ID.
This is what I manage to do so far.
% Define structure
points_data = struct('PointID', [], 'Coordinates', [], 'Names',[]);
% To have repeatable data
rng (0)
% Fill the data
for i = 1:10
% generate random coordinates
rand_coord = rand(1,3,'double');
points_data.PointID(end+1) = i;
points_data.Coordinates{end+1} = rand_coord;
points_data.Names{end+1} = ['Point', num2str(i)];
end
% Display all data with PointID 2
points_data{points_data.PointID==2}
But this code produce error if I try to access via PointID == 2. The only other way I can think of is to create a cell array so that each element in this cell array is Point structure.
What is your advice?
1 commentaire
Askic V
le 12 Oct 2022
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Characters and Strings dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!