matlab - Calculate a "running" maximum of a vector -


I have the following metrics that keep track of the start and end points of the data categories (first column "" < / Code> and represents the second column "end" ):

  myMatrix = [162 199; % // This range is 162: 199 166 199; % // This range is 166: 199 180 187; % // and so on ... 314 326; 323 326; 397 39 9; 41 9 420; 433 436; 576757; 57 9 630; 634 757; 663 757; 668 757; 676 714; 722 757; 746 757; 79 9 806; 951 953; 1271 1272];   

I need to eliminate all the categories (i.e. rows) which are present within a large range present in the matrix. For example the limits are contained within the [166: 199] and [180: 187] [162: 199] and thus, Rows 2 and 3 will need to be removed.

What I thought I thought was to calculate "running" max on the second column, for which the value after the column was to decide that Need to remove or not. I used it for the loop as follows:

  currentMax = myMatrix (1,2); % // Maximum value size [size of matrix, ~] = size (mimetric); To determine the number of% // rows, Tomorrow = false (sizeoffmatrix, 1); Assign logical final vector for% 2 = 2: Size IFMatrix if matrix (M, 2) & gt; CurrentMax% // If the new maximum has reached, update the current max ... currentMax = myMatrix (m, 2); (M) = true for other rows; % // ... and mark that row to end the mark myMatrix (rowsToRemove, :) = [];   

This removes "unnecessary" categories in " metatix ​​ and generates the following metrics:

  myMatrix = 162 199 314 326 397 399 419 420 433 436 576 757 79 9 806 951 953 1271 1272 Questions:  

1) It appears that there should be a better way to "walk" " max. Calculating for loop from I looked at accumarray and filter , but there is no way to do this with those tasks Could Is there a possible alternative which leaves the loop (any type of vector code which is more efficient)?

2) Is there a completely different (which is more efficient) way to fulfill the ultimate goal of removing all the categories contained in large categories in myMatrix ? I do not know if I'm thinking the whole thing ...

post-text itemprop = "text">

approach # 1

bxxfun based brute-force approach -

  myMatrix (zodiac (BSXFON (ge, my metrics (,, 1), matrix (:, 1) ) And ... bsxfan (@lay, my metrics (,, 2), matrix (:, 2) '), 2) & lt; = 1, :)   

Some clarifications on the proposed solution:

  1. All the start indexes against each other for "contained" Compare and similarly for the Ending Index, note that the "inherent" criteria should be for either of these two:

    • For more than or equal to and its equivalent or equal to ends
    • For less or equal and Ending is equal to

      I just have to go with the first option.

    • See which rows satisfy at least one "contained" and remove to remove the desired result.


      approach # 2

      If you are ok with an output that rows the rows according to the first column and if less The number of local maximum , you can try this alternative approach -

        myMatrix_sorted = sortrows (myMatrix, 1); Col2 = myMatrix_sorted (:, 2); Max_idx = 1: numel (col2); Whereas 1 col2_selected = col2 (max_idx); N = numel (col2_selected); Label = seamus ([true; difference (col2_selected)> 0]); Idx1 = Deposit (label, 1: n, [], @ (x) searchmax (x, cola 2 selected)); If the number (idx1) == N break; Maximum max_idx = max_idx (idx1); End = myMatrix_sorted (max_idx, :); % / Desired output   

      Associated function code -

        function ix = findmax (index, s) [~, ix] = max (index); Ix = Indx (ix); Return;    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -