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

5 views (last 30 days)
Kawalpreet Kaur on 26 Oct 2021
Answered: Pranjal Kaura on 29 Oct 2021
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 CommentsShowHide 1 older comment
Kawalpreet Kaur on 27 Oct 2021
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.

Pranjal Kaura on 29 Oct 2021
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!

### Categories

Find more on Legend in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by