Input with a file export the average
5 ビュー (過去 30 日間)
古いコメントを表示
I need to map the time from a text file to the time in a csv file and then output the average of those coordinates for that specific time.
2 input files: GPS.txt and Flight.csv
I want to take the second column of GPS.txt(the time whch is 08:08:55) and then look at 10 rows in h csv file where there are 10 data per second as the GPS.txt file has 1 sec resolution. I then average the 10 latitude information.
This is what I have so far...
%get user input to find matching long and lat
% Read in the data
data = read("DroneWork/flight.csv");
% Extract column D
colC = data(:, 3);
colD = data(:, 4);
colDate = data(:, 2);
prompt = "please input the date and time (yyyy-MM-dd HH:mm:ss): ";
dateandtime = input(prompt);
% Write out to a new workbook
xlswrite(outputFilename, Cmeans, 'latitude', 'A1');
xlswrite(outputFilename, Dmeans, 'longitude', 'A2');
%index of rows that match date and time
isDateTimeMatch = strcmpi(flightTable.date, dateandtime);
rowIdx = isDateTimeMatch;
if sum(rowIdx) == 0
error('No matches found.')
end
if sum(rowIdx) > 10
error('More than 10 matches found! Rows [%s].', num2str(find(rowIdx)))
end
%get latitude data with corresponding date
Cmeans = mean(colC2, 2);
%get longitude data with corresponding date
Dmeans = mean(colD2, 2);
%sum up long and lat and return the value
3 件のコメント
Vinai Datta Thatiparthi
2020 年 12 月 21 日
Hey Madison,
To echo @Matt's comments, it would be helpful if you could share some sample data for us to look at, along with a description of how you want the output data/Excel file to look like. Also, what is the specific issue that you're facing with this code that you've shared here?
Eric Sofen
2021 年 1 月 5 日
As above, example data and a more detailed explanation would be helpful. That said, I'd encourage you to use readtable/writetable (or go directly to readtimetable) rather than read/xlswrite. It sounds to me like you want to match one datetime to all datetimes within a 1s range? If so, check out timerange and withtol functions (and maybe dateshift) to accomplish this without needing to do text comparisons!
回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Spreadsheets についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!