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

1 次查看（过去 30 天）
Kawalpreet Kaur2021-10-26

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 个评论显示隐藏 1更早的评论
Kawalpreet Kaur 2021-10-27
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 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!

Community Treasure Hunt

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

Start Hunting!