in this array need to build an array a again but the value should not be less than or equal to 15 i need it
when i shift the value after adding my value which i have already added remain in the array like this
in 1st loop i have result lke this
how to get the right result with shifting
No products are associated with this question.
a = [10, 14, 5, 6, 7, 19]; r = zeros(size(a)); % Pre-allocate maximal length ri = 0; q = 0; for k = 1:length(a) q = q + a(k); % Accumulate values of "a" if q >= 15 % Flush accumulated value: ri = ri + 1; r(ri) = q; q = 0; end end r = r(1:ri); % Crop unused values
Play games and win prizes!Learn more