T = [0 0 0 2 3 4 0 0 0 5 2 1]; % input data T_out = zeros(size(T)); % find start and end indexes of groups of zeroes id_nonzero = (T>eps); [begin,ends] = find_start_end_group(id_nonzero); % loop over this groupes for k = 1:numel(begin) start = begin(k); % start index of k th groups of non zero values stop = ends(k); % end index of k th groups of non zero values T_out(stop) = sum(T(start:stop)); end T
T = 1×12 0 0 0 2 3 4 0 0 0 5 2 1
T_out
T_out = 1×12 0 0 0 0 0 9 0 0 0 0 0 8
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [begin,ends] = find_start_end_group(ind) % This locates the beginning /ending points of data groups % Important : ind must be a LOGICAL array D = diff([0;ind(:);0]); begin = find(D == 1); ends = find(D == -1) - 1; end
Matlabsolutions.com provides guaranteed satisfaction with a
commitment to complete the work within time. Combined with our meticulous work ethics and extensive domain
experience, We are the ideal partner for all your homework/assignment needs. We pledge to provide 24*7 support
to dissolve all your academic doubts. We are composed of 300+ esteemed Matlab and other experts who have been
empanelled after extensive research and quality check.
Matlabsolutions.com provides undivided attention to each Matlab
assignment order with a methodical approach to solution. Our network span is not restricted to US, UK and Australia rather extends to countries like Singapore, Canada and UAE. Our Matlab assignment help services
include Image Processing Assignments, Electrical Engineering Assignments, Matlab homework help, Matlab Research Paper help, Matlab Simulink help. Get your work
done at the best price in industry.