clear all; close all; clc %% Import data from text file. % Script for importing data from the following text file: % % D:\Descargas\Mega\Universidad\Cuarto\TFG\Matlab\OrbitaDelAsteroide\horizons_results.txt % % To extend the code to different selected data or a different text file, % generate a function instead of a script. % Auto-generated by MATLAB on 2016/04/23 09:42:55 %% Initialize variables. filename = 'D:\Descargas\Mega\Universidad\Cuarto\TFG\Matlab\OrbitaDelAsteroide\horizons_results.txt'; startRow = 2; %% Read columns of data as strings: % For more information, see the TEXTSCAN documentation. formatSpec = '%2s%2s%22s%4s%22s%4s%s%[^\n\r]'; %% Open the text file. fileID = fopen(filename,'r'); %% Read columns of data according to format string. % This call is based on the structure of the file used to generate this % code. If an error occurs for a different file, try regenerating the code % from the Import Tool. dataArray = textscan(fileID, formatSpec, 'Delimiter', '', 'WhiteSpace', '', 'HeaderLines' ,startRow-1, 'ReturnOnError', false); %% Remove white space around all cell columns. dataArray{1} = strtrim(dataArray{1}); dataArray{2} = strtrim(dataArray{2}); dataArray{4} = strtrim(dataArray{4}); dataArray{6} = strtrim(dataArray{6}); %% Close the text file. fclose(fileID); %% Convert the contents of columns containing numeric strings to numbers. % Replace non-numeric strings with NaN. raw = repmat({''},length(dataArray{1}),length(dataArray)-1); for col=1:length(dataArray)-1 raw(1:length(dataArray{col}),col) = dataArray{col}; end numericData = NaN(size(dataArray{1},1),size(dataArray,2)); for col=[3,5,7] % Converts strings in the input cell array to numbers. Replaced non-numeric % strings with NaN. rawData = dataArray{col}; for row=1:size(rawData, 1); % Create a regular expression to detect and remove non-numeric prefixes and % suffixes. regexstr = '(?.*?)(?([-]*(\d+[\,]*)+[\.]{0,1}\d*[eEdD]{0,1}[-+]*\d*[i]{0,1})|([-]*(\d+[\,]*)*[\.]{1,1}\d+[eEdD]{0,1}[-+]*\d*[i]{0,1}))(?.*)'; try result = regexp(rawData{row}, regexstr, 'names'); numbers = result.numbers; % Detected commas in non-thousand locations. invalidThousandsSeparator = false; if any(numbers==','); thousandsRegExp = '^\d+?(\,\d{3})*\.{0,1}\d*$'; if isempty(regexp(numbers, thousandsRegExp, 'once')); numbers = NaN; invalidThousandsSeparator = true; end end % Convert numeric strings to numbers. if ~invalidThousandsSeparator; numbers = textscan(strrep(numbers, ',', ''), '%f'); numericData(row, col) = numbers{1}; raw{row, col} = numbers{1}; end catch me end end end %% Split data into numeric and cell columns. rawNumericColumns = raw(:, [3,5,7]); rawCellColumns = raw(:, [1,2,4,6]); %% Exclude rows with blank cells I = any(cellfun(@(x) isempty(x) || (ischar(x) && all(x==' ')),rawNumericColumns),2); % Find row with blank cells rawNumericColumns(I,:) = []; rawCellColumns(I,:) = []; %% Exclude columns with blank cells J = any(cellfun(@(x) isempty(x) || (ischar(x) && all(x==' ')),rawNumericColumns),1); % Find columns with blank cells rawNumericColumns(:,J) = []; %% Initialize column outputs. columnIndices = cumsum(~J); %% Allocate imported array to column variable names VarName1 = rawCellColumns(:, 1); SO = rawCellColumns(:, 2); if ~J(1) E = cell2mat(rawNumericColumns(:, columnIndices(1))); end VarName4 = rawCellColumns(:, 3); if ~J(2) VarName5 = cell2mat(rawNumericColumns(:, columnIndices(2))); end VarName6 = rawCellColumns(:, 4); if ~J(3) VarName7 = cell2mat(rawNumericColumns(:, columnIndices(3))); end %% Clear temporary variables clearvars filename startRow formatSpec fileID dataArray ans raw col numericData rawData row regexstr result numbers invalidThousandsSeparator thousandsRegExp me rawNumericColumns rawCellColumns I J columnIndices; areal=[] for i=4:4:length(E) areal=[areal ; E(i)]; end areal; ereal=[] for i=1:4:length(E) ereal=[ereal ; E(i)]; end ereal; omreal=[] for i=2:4:length(E) omreal=[omreal ; E(i)]; end omreal; wreal=[] for i=2:4:length(VarName5) wreal=[wreal ; VarName5(i)]; end wreal; increal=[] for i=1:4:length(VarName7) increal=[increal ; VarName7(i)]; end increal; tareal=[] for i=3:4:length(VarName7) tareal=[tareal ; VarName7(i)]; end tareal; eor=[ereal areal increal omreal wreal tareal]; save elreal e-REdING. Biblioteca de la Escuela Superior de Ingenieros de Sevilla.


DISEÑO DE MISIONES DE RENDEZVOUS CON ASTEROIDES PRÓXIMOS A LA TIERRA

: Montilla García, José Manuel
: Grado en Ingeniería Aeroespacial
Contenido del proyecto: