I only want 1/4 of the data for one of my lines on my graph

1 view (last 30 days)
Hello, I don't have a lot of Matlab experience, but I was given a code that has two different sets of data, at to different sample rates. The instron data is taken at a rate of 20 points per second and the sensor data is taken at a rate of 80 points per second. I want to only take 1/4 of the sensor data so that the rates of both data sets match up, how would I do this ? anything helps !
% Import the data
for k=1:size(files)
TestSensor = readtable(files(k,1),opts);
TestInstron = readtable(files(k,2),opts_instron);
% transfer the table data to the array
sensor_data = table2array(TestSensor(2:height(TestSensor)-2,:));
instron_data = table2array(TestInstron(2:height(TestInstron),:));
% Plotting
%Pulling Force
plot(sensor_data_shift.*mask,sensor_data(:,3).*mask,'LineWidth',1.5,'Color',[0.267, 0.447, 0.769])% RGB Blue 68, 114, 196
hold on
%Normal Force
plot(instron_data(:,1)/SampleRate+gap,instron_data(:,3),'LineWidth',1.5,'Color',[0.929, 0.490, 0.192])% RGB Orange 237, 125, 49
% RGB Grey 165, 165, 165
legend('Normal Force','Pulling Force','Friction*1000')
grid on
ylabel('Force (lbs)')
hold off

Answers (1)

ILoveMATLAB on 23 Jun 2022
Edited: ILoveMATLAB on 30 Jun 2022
You should be able to do this using logical indexing. Please see the code below.
numOfRepetitions = round(length(instron_data )/ 4);
tfKeep = repmat([true false false false]', [numOfRepetitions,1]); % You may want [ false false false true]
tfKeep = tfkeep(1:length(instron_data),:);%Just in case the logical the array is too long
new_instron_data = instron_data(tfkeep,:)

Sign in to comment.




Community Treasure Hunt

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

Start Hunting!