How to add together values in matrix and replace the empty spaces with zeroes
I have used a code that was written in someone elses previous question, that adds together all values over 0, after each zero.
So if you had : [0 0 0 2 3 4 0 0 0 5 2 1], you would get [9 8]
However, what i would want is this [ 0 0 0 0 0 9 0 0 0 0 0 8]
So basically replacing the “open” spaces with a 0
Anyone know how i can achieve this?
NOTE:-
Matlabsolutions.com provide latest MatLab Homework Help,MatLab Assignment Help , Finance Assignment Help for students, engineers and researchers in Multiple Branches like ECE, EEE, CSE, Mechanical, Civil with 100% output.Matlab Code for B.E, B.Tech,M.E,M.Tech, Ph.D. Scholars with 100% privacy guaranteed. Get MATLAB projects with source code for your learning and research.
hello
try this :
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
SEE COMPLETE ANSWER CLICK THE LINK