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

조회 수: 1 (최근 30일)
Luis Huerta
Luis Huerta 2022년 6월 23일
댓글: ILoveMATLAB 2022년 6월 30일
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
%Friction
% RGB Grey 165, 165, 165
legend('Normal Force','Pulling Force','Friction*1000')
grid on
title(NamedGraphTitle)
xlabel('Time(s)')
ylabel('Force (lbs)')
axis([16.5,TimeendX,0,7500])
hold off
end

답변 (1개)

ILoveMATLAB
ILoveMATLAB 2022년 6월 23일
편집: ILoveMATLAB 2022년 6월 30일
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,:)
  댓글 수: 4
Luis Huerta
Luis Huerta 2022년 6월 30일
I haven't been able to fix it yet, i forgot to unaccept.
ILoveMATLAB
ILoveMATLAB 2022년 6월 30일
i updated the anwser

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Bar Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by