Loop to perform calculation from table data and store each result
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mark Maders
am 12 Jul. 2021
Bearbeitet: Cris LaPierre
am 13 Jul. 2021
I would like MATLAB to read a table from excel that contains travel arrival and depature data. From this data, I want to calculate the time between each arrival and the departure that follows. I wish to store each result in a new table. I have a very basic outline of what I am trying to achieve already.
I have another minor problem with the "remove first row if movement type is 'D'", with an error message stating:
Operator '==' is not supported for operands of type 'cell'.
Any help with these queries would be appreciated.
% import excel spreadsheet
T_Data = readtable('GGF1.xlsx');
% remove first row if movement type is 'D', else keep
if T_Data{1,1} == 'D'
T_Data{1,:} = [];
end
% -----------------------------------------------------------------------
% --- This will have to be updated to loop entire dataset and store each
% --- route time on ground.
% --- Loop should do row2 - row1; row4 - row3; row6 - row5 etc. and save
% --- each result in a new table
% take first route from the table for analysis
Route1 = T_Data(1:2,:);
% Determine time on ground for first route
OnGround = Route1{2,2} - Route1{1,2};
% -----------------------------------------------------------------------
0 Kommentare
Akzeptierte Antwort
Cris LaPierre
am 12 Jul. 2021
You are extracting arrays when you use curly braces. Use parentheses to keep the results in a table. See the Access Data in Tables documentation page.
MATLAB is determining the format of your first column to be cell. You can change this using setvartype.
% import excel spreadsheet
opts = detectImportOptions('GGF1.xlsx');
opts = setvartype(opts,"MovementType","categorical");
T_Data = readtable('GGF1.xlsx',opts);
% remove first row if movement type is 'D', else keep
if T_Data.MovementType(1) == 'D'
T_Data(1,:) = []
end
% Determine time on ground for first route
OnGround = diff(T_Data.Date_Time)
4 Kommentare
Cris LaPierre
am 13 Jul. 2021
Bearbeitet: Cris LaPierre
am 13 Jul. 2021
I'd create the logical index and new table doing something like this (untested)
T_Departures = T_Data(T_Data.MovementType=='D',:
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Type Identification finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!