Loop to perform calculation from table data and store each result
3 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
Cris LaPierre
2021-7-12
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 个评论
Cris LaPierre
2021-7-13
编辑:Cris LaPierre
2021-7-13
I'd create the logical index and new table doing something like this (untested)
T_Departures = T_Data(T_Data.MovementType=='D',:
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Data Type Identification 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!