简体   繁体   中英

adding the values in a matrix based on the corresponding unique values of another matrix

e=[40 19 18 20 30 34 65 97 155 160];

If there is a minimum difference between two consecutive values (for eg (19,18), (30, 34) and (155,160)) then merge these values..

Similar values also...Whatever condition can be used to solve this..Kindly help to solve this..

Iteratively,

e = [ 40 19 18 20 30 34 65 97 155 160];
current = e + 1; % init
prev = e;
while ~isequal( current, prev )
    prev = current;
    d = [ diff( prev ) < 5 true]; % always keep the last one
    current = prev( d );
end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM