Results 1 to 7 of 7

Math Help - Finding max min values

  1. #1
    Member disclaimer's Avatar
    Joined
    Dec 2007
    Posts
    77

    Finding max min values

    Hi, I need a script that will let me find extreme values based on measurements. The experiment involved a piston moving horizontaly left/right right/left repeatedly. During the experiment, its position was measured, to make it clear it would be something like this:

    1st cycle: -40 -36 -30 ... -4 0 3 ... 31 38 42
    2nd cycle: -41 -37 -29 ... -3 0 4 ... 32 39 44

    and so on...

    Those are just some random values to help illustrate the problem. I have over 30,000 values for a number of cycles so it's just impossible to go through all of them. It's supposed to be done in Matlab. Some while/if loops whould do I guess, but once I start nesting them I always get lost. Help appreciated.
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    Try something like this if you want the min and max of each cycle. If you just want the min max of everything, then you can just repeat the operation again I think.

    Code:
    A = [-40 -36 -30 -4 0 3 31 38 42;-41 -37 -29 -3 0 4 32 39 44]
    min_max = [min(A')' max(A')']%get min max for each cycle
    Code:
    A =
    
       -40   -36   -30    -4     0     3    31    38    42
       -41   -37   -29    -3     0     4    32    39    44
    
    
    min_max =
    
       -40    42
       -41    44
    Elbarto
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Member disclaimer's Avatar
    Joined
    Dec 2007
    Posts
    77
    Thanks for you help but I guess I forgot to mention some important details.
    Assume I have a 1x32000 matrix A. It contains all the measured values. I don't know how many cycles were performed, I don't know how many measurements were taken in each cycle either. But I can tell for sure that measurements for each cycle don't have to be "symmetrical" with respect to 0, I mean for example:


    1st cycle: -40 -36 -30 -4 0 3 31 38 42
    2nd cycle: -41 -37 -29 -18 -3 0 4 32 44


    My first concept was something like this:

    Code:
    i = 3;
    
    while i<=32000;
        
        if A(1,i-2)>A(1,i-1); A(1,i-1)<A(1,i);
            m_i_n=A(1,i-1);
            
        end
        
        if A(1,i-2)<A(1,i-1); A(1,i-1)>A(1,i);
            m_a_x=A(1,i-1);
        end
        
        i=i+1;
        
    end

    I guess all I need now is a matrix that will let me "catch" all those intermediate values but I don't know what syntax to use.
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Member
    Joined
    Mar 2007
    Posts
    206
    Awards
    1
    can you upload a .mat or .txt file with an example of your data by any chance?
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by disclaimer View Post
    Thanks for you help but I guess I forgot to mention some important details.
    Assume I have a 1x32000 matrix A. It contains all the measured values. I don't know how many cycles were performed, I don't know how many measurements were taken in each cycle either. But I can tell for sure that measurements for each cycle don't have to be "symmetrical" with respect to 0, I mean for example:


    1st cycle: -40 -36 -30 -4 0 3 31 38 42
    2nd cycle: -41 -37 -29 -18 -3 0 4 32 44


    My first concept was something like this:

    Code:
    i = 3;
     
    while i<=32000;
     
        if A(1,i-2)>A(1,i-1); A(1,i-1)<A(1,i);
            m_i_n=A(1,i-1);
     
        end
     
        if A(1,i-2)<A(1,i-1); A(1,i-1)>A(1,i);
            m_a_x=A(1,i-1);
        end
     
        i=i+1;
     
    end

    I guess all I need now is a matrix that will let me "catch" all those intermediate values but I don't know what syntax to use.
    Try something like:

    Code:
    A0=A(1:length(A)-1);
    A1=A(2:length(A));
     
    mxidx=find((A0-A1)>0);
    mx=[A(mxidx),A(length(A)];
    mi=[A(1),A(mxidx+1)];
    CB
    Last edited by CaptainBlack; December 8th 2009 at 02:17 PM. Reason: Correct the code for bug
    Follow Math Help Forum on Facebook and Google+

  6. #6
    Member disclaimer's Avatar
    Joined
    Dec 2007
    Posts
    77
    Quote Originally Posted by CaptainBlack View Post
    Try something like:

    Code:
    A0=A(1:length(A)-1);
    A1=A(2:length(A));
     
    mxidx=find((A0-A1)>0);
    mx=A(mxidx);
    mi=[A(1),A(mxidx+1)];
    CB
    Well, thank you but it doesn't give me exactly what I'm looking for. It just creates two matrices and puts every single value in either of them.

    Cause the truth is that, while executing the script I posted, Matlab assigns a min/max value for each iteration performed. That gives us "false" min/max values I guess.

    Quote Originally Posted by elbarto View Post
    can you upload a .mat or .txt file with an example of your data by any chance?
    Check the attachment.

    Thank you both for your help.
    Attached Files Attached Files
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by disclaimer View Post
    Well, thank you but it doesn't give me exactly what I'm looking for. It just creates two matrices and puts every single value in either of them.
    Now that does not agree with my results, even with the bug still in it does not do what you say for me.

    Code:
    --> A
    
    ans = 
     
    Columns 1 to 14
    -40 -36 -30  -4   0   3  31  38  42 -40 -36 -30  -4   0                         
    Columns 15 to 27
    3  31  38  42 -40 -36 -30  -4   0   3  31  38  42
    
    --> A0=A(1:length(A)-1)  
    
    A0 =  
    Columns 1 to 14 
    -40 -36 -30  -4   0   3  31  38  42 -40 -36 -30  -4   0 
    Columns 15 to 26
    3  31  38  42 -40 -36 -30  -4   0   3  31  38  
    
    --> A1=A(2:length(A)
    
    A1 =  
    Columns 1 to 14
    -36 -30  -4   0   3  31  38  42 -40 -36 -30  -4   0   3
    Columns 15 to 26
    31  38  42 -40 -36 -30  -4   0   3  31  38  42  
    
    --> mxidx=find((A0-A1)>0)
    
    mxidx = 9 18 
    
    --> mx=[A(mxidx),A(length(A))]
    
    mx =   42 42 42 
    
    --> mi=[A(1),A(mxidx+1)]  
    
    mi =   -40 -40 -40  
    
    -->
    Of course if the values are not increasing through a cycle this will not work.

    CB
    Last edited by CaptainBlack; December 8th 2009 at 02:34 PM.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. finding the max and min values
    Posted in the Calculus Forum
    Replies: 1
    Last Post: March 7th 2010, 03:33 PM
  2. Finding Values
    Posted in the Pre-Calculus Forum
    Replies: 6
    Last Post: November 21st 2009, 04:44 PM
  3. Finding values of x
    Posted in the Pre-Calculus Forum
    Replies: 1
    Last Post: November 7th 2009, 09:49 AM
  4. Finding the values of k???
    Posted in the Calculus Forum
    Replies: 1
    Last Post: March 31st 2008, 07:38 AM
  5. Finding values for A and B
    Posted in the Pre-Calculus Forum
    Replies: 1
    Last Post: September 16th 2007, 12:26 PM

Search Tags


/mathhelpforum @mathhelpforum