2

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: https://i.stack.imgur.com/QO78M.jpg

enter image description here

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
biggi_
  • 266
  • 3
  • 12

1 Answers1

1

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.

Divakar
  • 218,885
  • 19
  • 262
  • 358
  • When I try this I get the fact that 'x' is undefined which I agree with. However, earlier when importing data I am using: left_data = data(:,l); Could this be causing the problems? The fact that I am not really pulling the 'x' values in? – biggi_ Apr 19 '14 at 14:28
  • You have used `x` in your code. What does `x` mean to you? – Divakar Apr 19 '14 at 14:30
  • I have labled the xaxis, but other than that I do not have 'x' in my code. if you look everywhere it's either (:,l) or [~,r]. You have any other idea why it is not working? – biggi_ Apr 19 '14 at 14:32
  • Ok that prints min and max index are both 50, which seems to be correct if you look at my graph, so that part seems correct, however I am still also wanting to be able to look at each of the individual graphs separately and have like `Left Knee 1 = value` and `Left Knee 2 = value 2` and have it display those. Is that possible? – biggi_ Apr 19 '14 at 14:45
  • Looking back at your graph, I think you need to use `x` as `left_avg` and get the min/max and the indices for it. Then repeat it with `right_avg`, that is take x as `right_avg` and get min/max and the indices. Remember to use diferent variable names for `left_avg` and `right_avg` cases or else you would be over-writing. – Divakar Apr 19 '14 at 14:56
  • I realized that a minute ago and already implemented that :D But the question still remains, is it possible to look at each of the individual graphs (the top 2 graphs) and do the same for each one, storing the max/min to different values? Something like `Left1 = value` and `Left2 = value`? – biggi_ Apr 19 '14 at 14:57
  • @Check out **Edit 1** if that helps! – Divakar Apr 19 '14 at 16:16
  • Awesome man, that did exactly what I needed to, now I can export that data out back to an Excel sheet and replot it. I would upvote you if I could, but I don't have enough rep yet =( – biggi_ Apr 19 '14 at 17:34
  • Wow awesome! Finally it's done! Don't worry about upvoting, no rush on that. Accepting answer would work just fine I think. – Divakar Apr 19 '14 at 17:37