Am trying to reduce a vector by summing some elements in the vector to form another vecter

1 visualización (últimos 30 días)
example if v=[40,34,10,8,6,2] then the new vector will make 40 to be the reference point. after comparing each element the new vector will be N=[40,34,26]
  6 comentarios

Iniciar sesión para comentar.

Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 15 de Nov. de 2017
Editada: Andrei Bobrov el 15 de Nov. de 2017
b = cumsum(hankel(v));
k = max(b .* (b <= 40));
N = k(cumsum(k) <= b(end,1));
or
t = cumsum(hankel(v));
t = max(t.*(t <= 40));
N = t(cumsum(t) <= sum(v));
  2 comentarios
Bashir Yusuf Bichi
Bashir Yusuf Bichi el 16 de Nov. de 2017
pls if I have a vector a=[30.85,4.11,6.17,2.51,2.28]; b=sum(a)/numel(a); I want to find the closes value to the average b and its indices, what will I do?
Andrei Bobrov
Andrei Bobrov el 16 de Nov. de 2017
a=[30.85,4.11,6.17,2.51,2.28];
b = mean(a);
t = a < b;
vals = a(t);
indices = find(t);

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by