Find min/max values for multiple vectors

8 views (last 30 days)
I have data that consists of 29000 data points, the data points represent knee flexion and extension while walking. I want to identify the range of knee flexion/extension for each step so would like to set up a code that will identify the max (peak knee flexion) and the min (essentially, the extreme of knee extension) and place them in columns so that I am able to mathematically determine the full range of motion. I have attached a small section of my data. Any help would be greatly appreciated.
Thank you,
KTATC
1.896891
1.906645
1.954969
2.017917
2.05585
2.026289
1.955361
1.86264
1.753541
1.651546
1.555886
1.434179
1.288468
1.099483
0.819409
0.414074
0.148248
0.525737
1.196841
1.94507
2.78589
3.716875
4.741009
5.88021
7.076109
8.230326
9.450791
10.936149
12.629765
14.395601
16.268884
18.356668
20.868518
23.78841
26.905872
30.152426
33.538209
36.958715
40.204742
43.213892
46.083349
48.813633
51.230342
53.17896
54.655308
55.696776
56.368171
56.78482
56.858641
56.517176
55.853492
54.819166
53.379501
51.595998
49.46196
47.008489
44.246653
41.173463
37.798069
34.202303
30.482646
26.800916
23.281601
19.81948
16.298334
12.786125
9.531466
6.522667
3.717017
1.303302
0.558666
1.40926
1.744807
1.383369
0.615887
0.526611
1.856527
3.167393
3.48183
2.653554
1.688529
1.820048
3.239606
5.196485
6.914517
8.316931
9.252989
9.275997
8.446561
7.208222
5.901303
4.92285
4.578578
4.748885
4.969603
4.880134
4.641839
4.374502
3.898061
3.308544
2.646962
1.972139
1.321713
0.687884
0.201645
0.162774
0.502434
0.822817
1.016835
1.138862
1.24153
1.334558
1.430215
1.48632
1.455194
1.358422
1.247557
1.108878
0.996499
0.901696
0.771448
0.629032
0.469211
0.215851
0.175029
0.641086
1.31688
2.1296
3.065699
4.160619
5.364495
6.668968
7.961354
9.201787
10.660482
12.307979
13.843011
15.39884
17.25659
19.433607
21.917437
24.704024
27.751515
31.090369
34.626633
38.131851
41.342198
44.176488
46.894787
49.527243
51.878779
53.700516
54.983319
55.826943
56.315017
56.557513
56.429544
56.010607
55.325851
54.300641
52.894947
51.113024
49.032677
46.646148
43.950462
40.9241
37.663488
34.285807
30.846671
27.337066
23.81088
20.261188
16.663554
13.064789
9.595202
6.415074
3.471567
1.064811
0.905657
2.087995
2.551736
2.315807
1.519399
0.539398
1.003327
2.245342
2.515882
1.620003
0.700727
0.975712
2.428847
4.398375
6.193811
7.564108
8.296403
8.054285
7.118903
6.090608
5.191819
4.496392
  4 Comments
Walter Roberson
Walter Roberson on 29 Jun 2012
I think it means the peaks of the vector represent the extreme in one case, and the troughs represent the extreme in the other case.
Kathy
Kathy on 29 Jun 2012
Hi all, thank you for the comments and answers. This is for my research and I have used the findpeaks command, the findvalleys command was kind of a pain to use so I will try the suggestions provided below. Yes, the peak value does represent the extreme in this case, knee flexion, and the troughs represent the extreme in knee extension. In my 29000 data points there are approximately 295 strides (consisting of R and L leg knee flexion/extension) and I want to find the extreme values for each of the strides..... in answer to Holei's question, I do have multiple 29000 data point files (14 subjects in all) and 2 columns (R leg, L leg) for each subject.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 29 Jun 2012
I had some fun with this, since I used a similar strategy for my own research not long ago. See 'findpeaks' (I think it's in the Signal Processing Toolbox) to check out its options. You might be able to make it do exactly what you want.
The code:
[YOUR KTATC VECTOR GOES HERE]
xvct = 0:length(KTATC)-1; % Create a reference x-vector
[PeaksKTATC, PeaksIdx] = findpeaks(KTATC); % Find peaks of KTATC
FlipKTATC = 1.001*max(KTATC)-KTATC; % Flip it upside down to turn Valleys into Peaks
[ValleyKTATC1,ValleyIdx] = findpeaks(FlipKTATC); % Find Valleys
ValleyKTATC = 1.001*max(KTATC)-ValleyKTATC1; % Reconstitute Valley values
figure(205)
plot(xvct, KTATC)
hold on
plot(xvct(PeaksIdx), KTATC(PeaksIdx), '+r')
plot(xvct(ValleyIdx), KTATC(ValleyIdx), '+g')
hold off
legend('Knee Goniometry Data', 'Peaks', 'Valleys')
grid
Putting your data in columns is likely to be a bit more of a challenge, since they're not all going to be equal. I didn't address that because after plotting your data, I don't know what you want to define as where your data vectors start and stop.
There are several ways to go about this, creating a cell array is likely the easiest. That wasn't the way I opted to work with my data (for the time being at least), preferring instead to create a 'zeros' matrix with the column length defined by the longest data column. I keep a separate matrix of the original data set start times and indices, stop times and indices, and lengths of the various data vectors. My routines are set up to load and work with those data in their matrix form.
  2 Comments
Kathy
Kathy on 29 Jun 2012
Thank you. I have used the findpeaks function and it works very nicely with my data although I do have to establish a 'minpeakdistance' so that each peak isn't picked up. There is an option to provide peak values and locations to check your data... was hoping I might be able to accomplish something like that with this. I am going to try it now.
Thank you again.
Star Strider
Star Strider on 29 Jun 2012
Edited: Star Strider on 29 Jun 2012
My pleasure! I plotted your data because I was curious to see what it looked like. The answer was fairly straightforward after that. The relatively high-frequency ringing at full extension was interesting.
Thank you for accepting my answer.

Sign in to comment.

More Answers (1)

Walter Roberson
Walter Roberson on 29 Jun 2012
Do peak detection. Then take the negative of the data and do peak detection on that in order to find the locations of the troughs.
  1 Comment
Kathy
Kathy on 29 Jun 2012
Thank you, funny both you and Star Strider answered similarly.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!