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

조회 수: 5(최근 30일)
Kawalpreet Kaur 2021년 10월 26일
답변: Pranjal Kaura 2021년 10월 29일
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!