How can I interpolate the two data in the timetable? (Interpolate Data with 0 value, not data of Nan value)

3 visualizaciones (últimos 30 días)
How can I interpolate the two data in the timetable?
Instead of interpolating the data with the value of Nan, I want to replace the data marked with value '0' into the interpolated value using the data before and after.
This is my Code. and my time table example
% 코딩의 기준 : DATA 자동화 해주기.
% 제일 중요한 기준 : Timeline.xlsx 파일의 delta_T를 이용하여 GPS와 Lidar의 TimeTable 제작
% 이때 TimeTable은 시간 기준을 Timeline 파일의 delta_T에 맞춰서 시간만큼 빼거나 늦춰줘야함.
% GPS를 먼저 TimeTable화 하기. (Datestr 함수 사용해야할 것으로 생각됨.)
% 엑셀 파일에서 최대한 건들지 않고 자동화 될 수 있도록 짜보기.
% 그 다음에 Lidar를 TimeTable화 하기. (.txt 파일을 그대로 사용) (보완 필요)
% 두 Timetable의 값들중 필요한 것만 빼서, GPS Time을 기준으로 Synchronize함수 사용해주기. (GPS 데이터가 모든 Time을 포함하고 있으므로)
% Synchronize화되면, ismissing 함수를 이용하여 Lidar 데이터의 누락된 값들을 빼주기.
% 합성된 TimeTable을 가지고 Plot화 하기.
%-------------------------------------------------------------------------------------------------------------------
% Post-Processing 필요 목록 :
% GPS 엑셀 파일 목차들 다 한국어 -> 영어로 변환해주기.
% Lidar 텍스트 파일 -> 엑셀 파일로 변환해주기 (띄어쓰기를 구분으로 탭 나누기)
% Get Delta_T data
Timeline = xlsread('Timeline(Example file).xlsx'); % Timeline 엑셀 파일 넣어주기.
Lidar_DeltaT = Timeline(2, 1);
GPS_DeltaT = Timeline(3, 1);
% Get speed data
opts = detectImportOptions('GPS Cycle(Example file).xlsx'); % GPS 엑셀 파일 넣어주기
opts.VariableTypes = {'double','datetime','double','double','double','double','double','double','double'};
GPS = readtimetable('GPS Cycle(Example file).xlsx',opts); % GPS 엑셀 파일 넣어주기
GPS.Date = GPS.Date - seconds(GPS_DeltaT); % adjust Delta_T
GPS = retime(GPS,"secondly","fillwithconstant","Constant",0);
% Get distance
opts = detectImportOptions('Lidar Cycle(Example file).xlsx'); %라이다 엑셀 파일 넣어주기
opts.VariableNames = ["Var1", "Var2", "Date", "Var4", "Day", "Var6", "Time", "Var8", "Var9", "Var10", "Distance", "Unit"];
opts.SelectedVariableNames = ["Date", "Time", "Distance"];
opts.VariableTypes = ["categorical", "char", "datetime", "char", "categorical", "char", "duration", "char", "categorical", "char", "double", "categorical"];
opts = setvaropts(opts,"Time","DurationFormat","hh:mm:ss.S");
Lidar = readtimetable('Lidar Cycle(Example file).xlsx',opts); %라이다 엑셀 파일 넣어주기
Lidar.Date = Lidar.Date + Lidar.Time; % combine Date + Time data
Lidar.Date = Lidar.Date - seconds(Lidar_DeltaT); % adjust Delta_T
Lidar = retime(Lidar,"secondly","fillwithconstant","Constant",0);
Lidar = removevars(Lidar,"Time");
% merge the GPS and Lidar data
comb = synchronize(GPS,Lidar); % 두 데이터 규합
Comb_modified = fillmissing(comb, 'lnear',
% Create plot
figure(1)
plot(comb.Date,comb.Distance, 'Color', 'r') % 규합된 데이터의 날짜와 거리 데이터 빼서 그래프
title('Lidar Distance Plot')
ylabel("Distance (cm)", 'Color', 'r')
xlabel("Time (hh:mm:ss)")
figure(2)
plot(comb.Date,comb.Speed_km_h_, 'Color', 'b') % 규합된 데이터의 날짜와 속도 데이터 빼서 그래프
title('GPS Velocity(km/h) Data Plot')
ylabel("Velocity (km/h)", 'Color', 'b')
xlabel("Time (hh:mm:ss)")
figure(3)
yyaxis left
plot(comb.Date,comb.Distance)
ylabel("Distance (cm)" )
xlabel("Time (hh:mm:ss)")
yyaxis right
plot(comb.Date,comb.Speed_km_h_ )
ylabel("Velocity (km/h)")
xlabel("Time (hh:mm:ss)")
xtickformat("hh:mm:ss")
title('Velocity(km/h) & Distance Comb Plot')
% With Cris LaPierre's help, the code works perfectly. It was a great help.
I want to transform the values of '0' in the Distance item of Timetable into interpolated values.
In my case, since I want to change the data with the value of 0, not the value of Nan, to the interpolated data, it was difficult to solve with the MATLAB code explanation. So I ask for your advice.

Respuestas (1)

Cris LaPierre
Cris LaPierre el 30 de Ag. de 2020
Editada: Cris LaPierre el 31 de Ag. de 2020
Perhaps use interp2?
indRef = ~ismissing(comb.Latitude) & comb.Distance > 0;
indPred = ~ismissing(comb.Latitude) & comb.Distance == 0;
comb.Distance(indPred) = interp2(comb.Latitude(indRef),comb.Longitude(indRef),comb.Distance(indRef),...
comb.Latitude(indPred),comb.Longitude(indPred));
I'll just caution that this code is untested.
  2 comentarios
Jingyu Yang
Jingyu Yang el 30 de Ag. de 2020
Editada: Jingyu Yang el 30 de Ag. de 2020
How about using 'filloutliers' function?
Comb_modified = filloutliers(comb, 'linear', 'DataVariables','Distance', 0);
And... also it fails... T.T
And I used your codes, and I got some error messages :
다음 사용 중 오류가 발생함(Error occured) : griddedInterpolant
입력 좌표 배열의 수는 샘플 값의 차원과 일치해야 합니다. (The number of input coordinate arrays must match the dimensions of the sample value.)
오류 발생(Error occured): interp2>makegriddedinterp (line 228)
F = griddedInterpolant(varargin{:});
오류 발생(Error occured): interp2 (line 128)
F = makegriddedinterp({X, Y}, V, method,extrap);
오류 발생(Error occured): Auto_GPS_Lidar_Data_merge_Code (line 54)
comb.Distance(indPred) = interp2(comb.Latitude(indRef),comb.Longitude(indRef),comb.Distance(indRef),...
Cris LaPierre
Cris LaPierre el 31 de Ag. de 2020
That's a good idea. I would try fillmissing instead of filloutlier. That means you have to turn the 0's into missing first.
indPred = ~ismissing(comb.Latitude) & comb.Distance == 0;
comb.Distance(indPred) = missing;
comb.DistanceNew = fillmissing(comb.Distance,'linear');
This approach is going to assume continuity between the neighboring values.

Iniciar sesión para comentar.

Categorías

Más información sobre Labeling, Segmentation, and Detection en Help Center y File Exchange.

Productos


Versión

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by