Hello, How can I make the output timetable look similar in the photo, so it will 901*1 instead of 901*3
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Reham Wafaee
el 25 de Mayo de 2024
Comentada: Star Strider
el 25 de Mayo de 2024
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);
0 comentarios
Respuesta aceptada
Star Strider
el 25 de Mayo de 2024
You can do that once, however if you write it and then read it, it will lose the original formatting.
To illustrate —
Time = datetime('now') + seconds(0:10:80).';
Time.Format = 'ss';
Time = Time - Time(1);
LLA = rand(numel(Time),3);
aircraftTT = timetable(LLA, 'SampleRate',0.1)
writetimetable(aircraftTT, 'Aircraft.xlsx')
aircraftT2 = readtable('Aircraft.xlsx');
aircraftT2.Time = seconds(cellfun(@str2double, regexp(aircraftT2.Time, '\d*', 'match')));
aircraftTT2 = table2timetable(aircraftT2)
.
2 comentarios
Más respuestas (1)
Abhishek Kumar Singh
el 25 de Mayo de 2024
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!
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!