I want to generate a data structure array from data but I got an error.

>> for(ind=1:2)
[data(ind)] = generate_data_struct;
end
NEO_orb_index = 1;
EARTH_orb_index = 2;
%=========================================================================%
%=========================================================================%
data(NEO_orb_index).a = 9.22145e-01; %
data(NEO_orb_index).e =1.91191e-01 ; %
data(NEO_orb_index).i =3.33074 ; %
data(NEO_orb_index).RAAN = 2.04194e+02; %
data(NEO_orb_index).arg_peri =1.26476e+02 ; %
data(NEO_orb_index).mean_anom =2.55165e+02 ; %
data(NEO_orb_index).mass =4e10 ; %
%=========================================================================%
data(EARTH_orb_index).a =9.99781e-01 ; % km
data(EARTH_orb_index).e = 1.64817e-02; %
data(EARTH_orb_index).i = 2.41701e-03; % deg
data(EARTH_orb_index).RAAN =2.24065e+02 ; % deg
data(EARTH_orb_index).arg_peri = 2.37735e+02; % deg
data(EARTH_orb_index).mean_anom =3.8029e+02 ; % deg
data(EARTH_orb_index).mass = 5.972e24; % kg
??? Undefined function or variable 'generate_data_struct'.

3 Comments

  • Is generate_data_struct a Matlab function?
  • The lines of code you show, are they the body of a function named generate_data_struct?
  • No where it is in the file but its seems to be
  • NoHere is the complete codes
%= Set meta simulation options. =%
%=========================================================================%
store_rel_pos_other = 0;
start_true_anom_scan_at_t_scan = 1;
%=========================================================================%
%= Set simulation parameters. =%
%=========================================================================%
%=========================================================================%
%= Error tolerance options for Matlab's ode45() numerical integrator. =%
%=========================================================================%
options = odeset('reltol',1*10^-13 , 'abstol',1*10^-9 );
%=========================================================================%
%= Time step at which the numerical integrator should store results. =%
%=========================================================================%
dt_sim =365 ; % [days]
%=========================================================================%
%= Load physical constants into the variable space. =%
%=========================================================================%
%physical_constants;
%=========================================================================%
%= Set the desired number of total sim objects, NOT counting the sun. =%
%=========================================================================%
num_obj = 2;
%=========================================================================%
%= Generate an unpopulated data structure for each object. =%
%=========================================================================%
for(ind=1:num_obj)
[orb_data(ind)] = generate_orb_data_struct;
end
%=========================================================================%
%= Generate unpopulated epoch data structures for NEO and all objects. =%
%=========================================================================%
[epoch_data_NEO] = generate_epoch_data_struct;
[epoch_data_INIT_ALL] = generate_epoch_data_struct;
%=========================================================================%
%= Generate unpopulated epoch data structure for event time. =%
%=========================================================================%
[epoch_data_EVENT] = generate_epoch_data_struct;
%=========================================================================%
%= Set the event time. =%
%=========================================================================%
epoch_data_EVENT.year = 2016; % [year]
epoch_data_EVENT.month =January ; % [month]
epoch_data_EVENT.day =01 ; % [day]
epoch_data_EVENT.hours = 00; % [hour (UT)]
epoch_data_EVENT.minutes =00 ; % [minutes (UT)]
epoch_data_EVENT.seconds =00 ; % [seconds (UT)]
epoch_data_EVENT.JD =2457388.50 ; % [JD]
epoch_data_EVENT.MJD = 57388; % [MJD]
%=========================================================================%
% Set the orbital data structure indices. =%
%=========================================================================%
NEO_orb_index = 1;
EARTH_orb_index = 2;
%=========================================================================%
%= Load orbital ephemeris data. =%
%=-----------------------------------------------------------------------=%
%= Note: The NEO is always the first in the array of data structures. =%
%=========================================================================%
%=========================================================================%
% >>>>>>>>>>>> NEO <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< %
%=========================================================================%
orb_data(NEO_orb_index).a = 9.22145e-01; % [km]
orb_data(NEO_orb_index).e =1.91191e-01 ; % [ - ]
orb_data(NEO_orb_index).i =3.33074 ; % [deg]
orb_data(NEO_orb_index).RAAN = 2.04194e+02; % [deg]
orb_data(NEO_orb_index).arg_peri =1.26476e+02 ; % [deg]
orb_data(NEO_orb_index).mean_anom =2.55165e+02 ; % [deg]
orb_data(NEO_orb_index).mass =4e10 ; % [kg]
%=========================================================================%
%= Set the epoch for the above NEO state information. =%
%=========================================================================%
epoch_data_NEO.year = 2016; % [year]
epoch_data_NEO.month = January; % [month]
epoch_data_NEO.day = 01; % [day]
epoch_data_NEO.hours =00 ; % [hour (UT)]
epoch_data_NEO.minutes =00 ; % [minutes (UT)]
epoch_data_NEO.seconds =00 ; % [seconds (UT)]
epoch_data_NEO.JD =2457388.50 ; % [JD]
epoch_data_NEO.MJD = 57388; % [MJD]
%=========================================================================%
% >>>>>>>>>>>> EARTH <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< %
%=========================================================================%
orb_data(EARTH_orb_index).a =9.99781e-01 ; % [km]
orb_data(EARTH_orb_index).e = 1.64817e-02; % [ - ]
orb_data(EARTH_orb_index).i = 2.41701e-03; % [deg]
orb_data(EARTH_orb_index).RAAN =2.24065e+02 ; % [deg]
orb_data(EARTH_orb_index).arg_peri = 2.37735e+02; % [deg]
orb_data(EARTH_orb_index).mean_anom =3.8029e+02 ; % [deg]
orb_data(EARTH_orb_index).mass = 5.972e24; % [kg]
%=========================================================================%
% >>>>>>>>>>>> ALL OTHER SIMULATION OBJECTS <<<<<<<<<<<<<<<<<<<<<<<<<<<<< %
%=========================================================================%
%
%=========================================================================%
%= Set the epoch for the initial state information for all objects other =%
%= than the NEO above. =%
%=-----------------------------------------------------------------------=%
%= Note: It is assumed that all objects other than the NEO, including =%
%= the Earth, have the same epoch for their initial conditions. =%
%=========================================================================%
epoch_data_INIT_ALL.year = 2016; % [year]
epoch_data_INIT_ALL.month =January ; % [month]
epoch_data_INIT_ALL.day =01 ; % [day]
epoch_data_INIT_ALL.hours =00 ; % [hour (UT)]
epoch_data_INIT_ALL.minutes =00 ; % [minutes (UT)]
epoch_data_INIT_ALL.seconds = 00; % [seconds (UT)]
epoch_data_INIT_ALL.JD =2457388.5 ; % [JD]
epoch_data_INIT_ALL.MJD =57388 ; % [MJD]
%=========================================================================%
%= Fully populate the orbital data structures. =%
%=========================================================================%
for(ind=1:num_obj)
[orb_data(ind)] = populate_orb_data_struct(orb_data(ind), mu_sun);
end
%=========================================================================%
%= Fully populate the epoch data structures. =%
%=========================================================================%
[epoch_data_NEO] = populate_epoch_data_struct(epoch_data_NEO);
[epoch_data_INIT_ALL] = populate_epoch_data_struct(epoch_data_INIT_ALL);
[epoch_data_EVENT] = populate_epoch_data_struct(epoch_data_EVENT);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
This is the code which I get from website
Google thinks that website is http://www.nss.org/resources/library/planetarydefense. Try to find the missing functions there.

Answers (1)

q = {9.2214e-001 9.9978e-001
1.9119e-001 1.6482e-002
3.3307e+000 2.4170e-003
2.0419e+002 2.2406e+002
1.2648e+002 2.3774e+002
2.5516e+002 3.8029e+002
4.0000e+010 5.9720e+024}
names = {'a';'e';'i';'RAAN';'arg_peri';'mean_anom';'mass'}
data = cell2struct(q,names,1)
or create function generate_data_struct:
function data = generate_data_struct(q,names)
data = cell2struct(q,names);
end

This question is closed.

Asked:

on 19 Apr 2016

Closed:

on 20 Aug 2021

Community Treasure Hunt

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

Start Hunting!