How to index txt file

22 views (last 30 days)
Sophia Starzynski
Sophia Starzynski on 21 Jul 2022
Commented: dpb on 21 Jul 2022
Hi everyone,
So I have data comming in at different frequencies in a txt file. I need to be able to index or filter through the data to only give me the data at 60 hz and delete the rows that are coming it at a higher frequency. The first column in the data is time in miliseconds which i have been using to filter the data to 60 hz. So basically I have make do an angorithum that will pick data points at x interval and exclude the other points,
time = data(:,1) ; % time column
datalength = length(data);
datalength2 = datalength - 1 ;
A = time(1:datalength2,1); % time data excluding last point
B = time(2:datalength,1); % time data excluding first point
C= B-A; % the vector that has the interval between each point
if C < 16
disp(' I < 16, deleting row')
% deleting row data(#of row,:) = []
else
disp(' I >= 16, keeping row')
end
this is what I have so far but i know it is wrong cause I can not get it to loop, and I do not know how to identify the row and delete the whole thing. I also have the txt file being imported as a matrix
Please let me know if you have any ihelp!

Answers (1)

dpb
dpb on 21 Jul 2022
datalength = length(data);
datalength2 = datalength - 1 ;
A = time(1:datalength2,1); % time data excluding last point
B = time(2:datalength,1); % time data excluding first point
C= B-A; % the vector that has the interval between each point
is more easily written in MATLAB as
dt=diff(time); % where I've named your variable C dt for 'delta-t'
which could also be
dt=diff(data(:,1)); % without the temporary time variable; use original
We don't have the input file to see, but one suspects
ttData=readtimetable('yourfile');
Fs=60;
ttD60=retime(ttData,'regular',method,'SampleRate',Fs);
should do it...
  2 Comments
Sophia Starzynski
Sophia Starzynski on 21 Jul 2022
it is giving me an error that it is unable to detect datetime or duration data in file
dpb
dpb on 21 Jul 2022
Well, we can't see the file, so as noted it was a guess...what's the input form? Easiest would be to attach the input file.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!