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 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 What I thought I thought was to calculate "running" This removes "unnecessary" categories in " 1) It appears that there should be a better way to "walk" " 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 bxxfun based brute-force approach - Some clarifications on the proposed solution: All the I just have to go with the first option. See which rows satisfy at least one "contained" and remove to remove the desired result. If you are ok with an output that rows the rows according to the first column and if less The number of Associated function code - "" < / 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];
[166: 199] and
[180: 187]
[162: 199] and thus, Rows 2 and 3 will need to be removed.
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, :) = [];
myMatrix = 162 199 314 326 397 399 419 420 433 436 576 757 79 9 806 951 953 1271 1272 Questions:
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)?
myMatrix ? I do not know if I'm thinking the whole thing ...
approach # 1
myMatrix (zodiac (BSXFON (ge, my metrics (,, 1), matrix (:, 1) ) And ... bsxfan (@lay, my metrics (,, 2), matrix (:, 2) '), 2) & lt; = 1, :)
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
and
Ending is equal to
approach # 2
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
function ix = findmax (index, s) [~, ix] = max (index); Ix = Indx (ix); Return;
Comments
Post a Comment