Clear Filters
Clear Filters

Info

This question is closed. Reopen it to edit or answer.

Define the functions in the code in a specific manner (is given below).

1 view (last 30 days)
This question was flagged by Voss
Can you define the following 3 vectorized functions in the code: launch_yr_4d(y2d), apogee, and perigee. Make it similar to the format of this.
function ave = calculateAverage(x)
ave = sum(x(:))/numel(x);
end
The code is below:
% Fetch TLE data from the URL
url_recent = 'https://celestrak.org/NORAD/elements/gp.php?GROUP=visual&FORMAT=tle';
line_list = string(splitlines(webread(url_recent)));
% Ensure line_list has a multiple of 3 number of lines for proper reshaping
line_list = line_list(1:floor(numel(line_list)/3)*3);
% Reshape the line list to separate each TLE into its own column
tle_data = reshape(line_list, 3, []);
% Define Constant used in function
earth_mean_radius = 6371; % km
% Define the functions: launch_yr_4d(y2d), apogee(mean_motion, eccentricity), perigee(mean_motion, eccentricity)
launch_yr_4d = @(y2d) (y2d >= 24) .* (1900 + y2d) + (y2d < 24) .* (2000 + y2d);
apogee = @(mean_motion, eccentricity) (8681663.653 ./ mean_motion) .^ (2/3) .* (1 + eccentricity) - earth_mean_radius;
perigee = @(mean_motion, eccentricity) (8681663.653 ./ mean_motion) .^ (2/3) .* (1 - eccentricity) - earth_mean_radius;
% Extract satellite numbers, launch years, eccentricities, and mean motions in batches
satellite_numbers = str2double(extractBetween(tle_data(2,:), 3, 7));
launch_years_2digit = str2double(extractBetween(tle_data(2,:), 10, 11));
launch_years = launch_yr_4d(launch_years_2digit);
eccentricities = str2double(extractBetween(tle_data(3,:), 27, 33)) * 0.0000001;
mean_motions = str2double(extractBetween(tle_data(3,:), 53, 63));
% Compute perigee and apogee heights in batches
hps = perigee(mean_motions, eccentricities);
has = apogee(mean_motions, eccentricities);
% Convert numerical values to strings with formatting
satNumStr = sprintfc('%05d', satellite_numbers);
launchYearStr = sprintfc('%04d', launch_years);
hpStr = sprintfc('%.2f', hps);
haStr = sprintfc('%.2f', has);
% Concatenate all string parts
outputStrings = strcat(satNumStr, " ", launchYearStr, " ", hpStr, " ", haStr, " ", string(tle_data(1, :)));
% Join and print all strings
fprintf('%s\n', join(outputStrings, newline));

Answers (0)

This question is closed.

Community Treasure Hunt

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

Start Hunting!