Selecting a section of data within an array and determining max and min values

2 views (last 30 days)
I am a novice user and am having some difficulty with my project.
I have a selection of data in which I need to determine the maximum and minimum values, and the corresponding latencies at which those values occur. Each array is 640 cells in length. Due to data collection procedures, a false max value may end up occurring within the first 10-50 cells (which is an artifact in the data). The true max and min should occur somewhere between cell 150 and 300. I have written the following code:
% code
Max_cutoff_SC=300
Min_cutoff_SC=100
Max_cutoff_MP=300
Min_cutoff_MP=100
Max_cutoff_Neck=200
Min_cutoff_Neck=50
%%Create neck data variable and take inverse%%
Neck1=SC_Top6(40:640,2); %Create variable for Neck data%
Neck1=Neck1.*-1;
Neck2=SC_Top6(40:640,4);
Neck2=Neck2.*-1;
Neck3=SC_Top6(40:640,6);
Neck3=Neck3.*-1;
%%Creating cortical variables and taking inverse%%
SC_Cortical1=SC_Top6(40:640,1);
SC_Cortical1=SC_Cortical1.*-1;
SC_Cortical2=SC_Top6(40:640,3);
SC_Cortical2=SC_Cortical2.*-1;
SC_Cortical3=SC_Top6(40:640,5);
SC_Cortical3=SC_Cortical3.*-1;
MP_Cortical1=MP_Top3(40:640,1);
MP_Cortical1=MP_Cortical1.*-1;
MP_Cortical2=MP_Top3(40:640,2);
MP_Cortical2=MP_Cortical2.*-1;
MP_Cortical3=MP_Top3(40:640,3);
MP_Cortical3=MP_Cortical3.*-1;
%%Find max and min values and latencies of corticals
[Max_amp_SC1,I_maxSC1]=max(SC_Cortical1(300:Max_cutoff_SC)); %N20 amplitude value and index value (which cell location)%
Time_max_SC1=T(I_maxSC1); %Gives time stamp of indexed value%
[Min_amp_SC1,I_minSC1]=min(SC_Cortical1(1:Min_cutoff_SC));
Time_min_SC1=T(I_minSC1); %Time at min value%
Abs_amp_SC1=Max_amp_SC1-Min_amp_SC1 %peak to peak value%
end
The problem is happening with the initial variables - the Max_cutoff series for SC, MP and Neck. When I change the values for these, the variables in the last series (Time_max, Time_Min, Abs_amp), are incorrect. That is to say, the max and min values that Matlab selects do not occur at the expected location. I feel as if the reading window is shifting, but I'm uncertain how to prevent this from happening. Essentially what I want to do is:
  • import excel file
  • have program omit the first 50 or so rows of data
  • examine the remaining data to find the maximum and minimum values
Any help on this matter would be very greatly appreciated!

Answers (2)

Image Analyst
Image Analyst on 5 Jun 2014
If you look at the max location in myArray(100:300), and it's, say 1, then you need to add 99 to get what index that would have been in the original myArray. So if the max in the shortened, extracted subarray is at 1, that would have been (1+99) = 100 in the original array

Star Strider
Star Strider on 5 Jun 2014
Edited: Star Strider on 5 Jun 2014
The max and min functions (with two output arguments) will only find the first occurrence of the maximum or minimum. To find others equal to it, use the find function.
Example:
A = [1 2 3 2 1 3 1 2 1 2 1 2 3];
[mx,mxix1] = max(A)
mxix2 = find(A == max(A))
produces:
mx =
3
mxix1 =
3
mxix2 =
3 6 13

Categories

Find more on Resizing and Reshaping Matrices 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!