Hello, How can I make the output timetable look similar in the photo, so it will 901*1 instead of 901*3
Ältere Kommentare anzeigen

mission.StartDate = datetime(2021,1,1,12,0,0);
missionDuration = 2.5;
mission.Duration = hours(2.5);
startLLA = [38.13425 140.44777 10000];
endLLA = [38.1499994 140.6333308 10000];
timeOfTravel = [0 3600*missionDuration];
sampleRate = 10; % The trajectory is sampled every 10 seconds.
trajectory = geoTrajectory([startLLA;endLLA],timeOfTravel,'SampleRate',sampleRate);
sampleTimes = timeOfTravel(1):sampleRate:timeOfTravel(end)
aircraftLLA = lookupPose(trajectory,sampleTimes)
% Add timestamps to the data and generate a timetable.
t = (0:sampleRate:timeOfTravel(end))';
tsec = seconds(t);
aircraftLLAin = [t aircraftLLA];
aircraftTT = array2timetable(aircraftLLA,"RowTimes",tsec);
Akzeptierte Antwort
Weitere Antworten (1)
You can modify last couple of lines in following way to get desired, add/modify the last couple of lines to use mergevars to get the 3 columns under one column.
Refer to the modified snippet below:
mission.StartDate = datetime(2021,1,1,12,0,0);
missionDuration = 2.5;
mission.Duration = hours(2.5);
startLLA = [38.13425 140.44777 10000];
endLLA = [38.1499994 140.6333308 10000];
timeOfTravel = [0 3600*missionDuration];
sampleRate = 10; % The trajectory is sampled every 10 seconds.
trajectory = geoTrajectory([startLLA;endLLA],timeOfTravel,'SampleRate',sampleRate);
sampleTimes = timeOfTravel(1):sampleRate:timeOfTravel(end);
aircraftLLA = lookupPose(trajectory,sampleTimes);
% Assuming aircraftLLA contains the LLA data and sampleTimes are defined
tsec = seconds(0:sampleRate:timeOfTravel(end))';
% Create a timetable directly with LLA data
aircraftTT = array2timetable(aircraftLLA, 'RowTimes', tsec, 'VariableNames', {'Latitude', 'Longitude', 'Altitude'});
% Now use mergevars to merge these variables under a single multicolumn variable
aircraftTT = mergevars(aircraftTT, {'Latitude', 'Longitude', 'Altitude'}, 'NewVariableName', 'AircraftLLA')
% Display the first few rows of the modified timetable to verify the structure
head(aircraftTT)
Here's what it looks like when you open the timetable from Workspace:

Refer to the documentation to know more: https://www.mathworks.com/help/matlab/ref/table.mergevars.html
Hope it helps!
1 Kommentar
Reham Wafaee
am 25 Mai 2024
Kategorien
Mehr zu Language Fundamentals finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!