Borrar filtros
Borrar filtros

how to multiply simplest way this two vectors ?

2 visualizaciones (últimos 30 días)
x y
x y el 3 de Dic. de 2014
Comentada: Stephen23 el 3 de Dic. de 2014
I have to multiply this xi and y this way:
xi = [98 99 100 101 102 103]; y = [2 4 6 4 3 1]; x = [ 98*ones(1,2), 99*ones(1,4), 100*ones(1,6), 101*ones(1,4),... 102*ones(1,3), 103*ones(1,1) ]
it is possible to somthing this to make.... x = xi.*( ones(1,y(1:end)) ) % this is not working

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 3 de Dic. de 2014
Editada: Azzi Abdelmalek el 3 de Dic. de 2014
xi = [98 99 100 101 102 103];
y = [2 4 6 4 3 1];
x=cell2mat(arrayfun(@(a,b) a*ones(1,b),xi,y,'un',0))
%or you can do it just by using a for loop

Más respuestas (2)

Guillaume
Guillaume el 3 de Dic. de 2014
Editada: Guillaume el 3 de Dic. de 2014
This is not a multiplication.
One of many ways to do what you want:
xi = [98 99 100 101 102 103];
y = [2 4 6 4 3 1];
x = cell2mat(arrayfun(@(v, r) repmat(v, 1, r), xi, y, 'UniformOutput', false))

Andrei Bobrov
Andrei Bobrov el 3 de Dic. de 2014
a = accumarray(cumsum([1; y(:)]),1);
x = xi(cumsum(a(1:end-1)));

Categorías

Más información sobre Multidimensional Arrays 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