필터 지우기
필터 지우기

Get separate index from a column with separate conditions

조회 수: 1 (최근 30일)
Hello, I have the following script with the attached files. I extracting two separate indexes from a column to find specific acceleration values values that matches the "index_initial_time" and "index_final_time" in a for loop. However, the second index ("index_final_time") is not capture properly, which does not allow to estimate the mean of the two acceleration values capture in the next lines. Could you please helpe on this. I would appreciate the help.
clear all
clc
SIGNAL = load('Time_Acceleration.txt');
X_spike_matrix=load('X_spike_matrix.txt');
n_spikes_X=height(X_spike_matrix);
TIME=SIGNAL(:,1);
ACCX=SIGNAL(:,2);
DT=TIME(2,1)-TIME(1,1);
ACCX_spikes_removed=ACCX;
for k=1:n_spikes_X;
initial_time_ACCX=X_spike_matrix(k,1)-DT; %t-DT time to corresponding acceleration value
final_time_ACCX=X_spike_matrix(k,1)+DT; %t+DT time to corresponding acceleration value
index_initial_time=find(TIME==initial_time_ACCX);
index_final_time=find(TIME==final_time_ACCX);
initial_ACCX=ACCX(index_initial_time,:); %t-DT acceleration to compute average replacement
%% line with issue
final_ACCX=ACCX(index_final_time,:); % t+DT acceleration to compute average replacement
%%
mean_ACCX_replacement=mean([initial_ACCX,final_ACCX]); %estimation of mean neibouring value to replace peak value
matrix_ACCX_neighbour_mean(k,1)=mean_ACCX_replacement; %acumulating corrected peak values in a matrix
ACCX_spikes_removed(TIME==X_spike_matrix(k,1))=mean_ACCX_replacement; %replacement of the peak value with the mean nenighbouring value
end
However, line 20 does not capture the next index value

채택된 답변

Matt J
Matt J 2023년 7월 21일
편집: Matt J 2023년 7월 21일
Remember, you are in a world of finite precision computers...
ftol=@(t) abs(TIME-t)<smallnumber; %compare to within a tolerance
index_initial_time=find( ftol(initial_time_ACCX) , 1);
index_final_time=find( ftol(final_time_ACCX) ,1,'last');

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by