Loop to perform calculation from table data and store each result
조회 수: 7 (최근 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!