Question

I have finally been able to get an Excel sheet read in and get the data plotted as needed and to get the data averaged. However, now I am having issues trying to find the local min and local max between values on the graph. I am trying to find the local min between say 20 and 50 and the local max between 50 and 100. Here is the code that I am using while bringing in the data:

filename = ('10070.xlsx');           %Opens the specified file
[data, text, ~] = xlsread(filename); %Gives a table for data and text
[~,l] = find(strcmp(text, 'Left Knee Angle'));
left_data = data(:,l);
subplot(2,2,1);
plot(left_data)
title({'Left Knee Angle'});
ylabel({'Angle'});
xlabel({'% of Trial'});
[~,r] = find(strcmp(text, 'Right Knee Angle'));
right_data = data(:,r);
subplot(2,2,2);
plot(right_data)
title({'Right Knee Angle'});
ylabel({'Angle'});
xlabel({'% of Trial'});
left_avg = mean(left_data,2);
subplot(2,2,3);
plot(left_avg)
title({'Left Knee Average Angle'});
ylabel({'Angle'});
xlabel({'% of Trial'});
right_avg = mean(right_data,2);
subplot(2,2,4);
plot(right_avg)
title({'Right Knee Average Angle'});
ylabel({'Angle'});
xlabel({'% of Trial'});

I have tried using:

[maxVal, maxIndex] = max(l(x>=20&x<=50));

But this has not worked for me. Anyone have any ideas/better ways to do this? Maybe I'm just typing something in incorrectly? I will also repeat the process for the other set of data (it is broken into left and right). Also, out of curiosity, is there a way to pull each one of the graphs in individually and find the local min/max from the individual graphs from left and right that are pulled in and average those? I'm just trying to think ahead on this. Here is a link to a screenshot of the graphs: http://i.imgur.com/SKep8Iy.jpg

enter image description here

Was it helpful?

Solution

Try this -

%%// Min-max index ranges
min_ind_range = [20 50];
max_ind_range = [50 100];

%%// Min value
[minVal, minIndex] = min(x(min_ind_range(1):min_ind_range(2)));
minIndex = minIndex+min_ind_range(1)-1

%%// Max value
[maxVal, maxIndex] = max(x(max_ind_range(1):max_ind_range(2)));
maxIndex = maxIndex+max_ind_range(1)-1

Edit 1: For a number of data as is the case with the upper two graphs, use this -

%%// Min-max index ranges
min_ind_range = [20 50];
max_ind_range = [50 100];

%%//  *** Left Case ***
%%// Min value
[left_minVal, left_minIndex] = min(left_data(min_ind_range(1):min_ind_range(2),:));
left_minIndex = left_minIndex+min_ind_range(1)-1;

[left_maxVal, left_maxIndex] = max(left_data(max_ind_range(1):max_ind_range(2),:));
left_maxIndex = left_maxIndex+max_ind_range(1)-1;

%%//  *** Right Case ***
%%// Min value
[right_minVal, right_minIndex] = min(right_data(min_ind_range(1):min_ind_range(2),:));
right_minIndex = right_minIndex+min_ind_range(1)-1;

[right_maxVal, right_maxIndex] = max(right_data(max_ind_range(1):max_ind_range(2),:));
right_maxIndex = right_maxIndex+max_ind_range(1)-1;

Please note that now we have a series of min-max values and their indices.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top