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

2 ビュー (過去 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 Center および File ExchangeBar Plots についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by