Finding the max value out of 1000 sample set at every second.

2 次查看(过去 30 天)
Hi,
I have a data set collected time versus strain. Strain data is collected at multiple points. So, I have one column for the X-axis and multiple columns for the Y-axis.
The sample data is collected 1000 times every second. I want to get the maximum value for strain at every second (out of 1000 samples) and plot it against the time. The test runs for 4 hours, so I want to convert the time from seconds to hours.
So, there will be multiple lines for the Y-axis in the plot.
I am looking forward to any help.
Thanks
  2 个评论
VBBV
VBBV 2021-10-27
for i = 1:10
xy(:,i) = unidrnd(1000,1000*60*60,1); % strain data
end
T =1:length(xy)/1000; % time data
[V I] = max(xy(1:1000:end,:))
V = 1×10
1000 1000 1000 1000 1000 1000 1000 999 1000 1000
I = 1×10
768 54 56 2044 226 133 5 3339 1871 870
plot(T(I),V)
Try this
Kawalpreet Kaur
Kawalpreet Kaur 2021-10-27
Thank you for your reply. I appreciate it.
Let me put my question in this way.
I have a data set collected time (VarName2) versus strain (VarName3, VarName4, VarName5, VarName6..... and so on until col U). So, I have one column for the X-axis and multiple columns for the Y-axis.
The sample data is collected 1000 times every second. I want to get the maximum value for strain at every second (out of 1000 samples) and want to plot the graph time on X axis (convert from seconds to hours) and on Y axis (all the strain values representing in different columns). I have million of rows for this data set.
I am looking forward to any help. Thank you.

请先登录,再进行评论。

回答(1 个)

Pranjal Kaura
Pranjal Kaura 2021-10-29
Hey Kawalpreet,
You can refer to the following code snippet wherein I've tried to replicate your usecase and provided a solution.
sample_rate = 10; %1000 for you
num_rows = 1000; %1 million for you
pd = makedist('Normal');
VarName3 = random(pd, [num_rows, 1]);
VarName4 = random(pd, [num_rows, 1]);
dataset = [VarName3 VarName4];
dataset_sampled = reshape(dataset, sample_rate, num_rows/sample_rate, size(dataset, 2));
dataset_sampled_max = squeeze(max(dataset_sampled, [], 1));
time_sec = 1:length(dataset_sampled_max);
time_hours = time_sec/3600;
plot(time_hours, dataset_sampled_max);
xlabel("Time in Hours");
You can refer to the 'plot' documentation to know more about addings labels, legends, color etc to the plot.
Hope this helps!

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by