Clear Filters
Clear Filters

Get separate index from a column with separate conditions

1 view (last 30 days)
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

Accepted Answer

Matt J
Matt J on 21 Jul 2023
Edited: Matt J on 21 Jul 2023
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');

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!