Octave / Matlab: ¿Extender un vector haciendo que se repita?


¿Hay una manera de extender un vector haciendo que se repita?

>v = [1 2];
>v10 = v x 5; %x represents some function. Something like "1 2" x 5 in perl

Entonces v10 sería:

>v10
     1 2 1 2 1 2 1 2 1 2

Esto debería funcionar para el caso general, no solo para [1 2]

Author: BЈовић, 2010-03-17

2 answers

La función que estás buscando es repmat().

v10 = repmat(v, 1, 5)
 133
Author: Andrew Shepherd,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-01-04 18:26:10

Obviamente repmat es el camino a seguir si sabes en qué dirección quieres expandir el vector.

Sin embargo, si desea una solución general que siempre repita el vector en la dirección más larga, esta combinación de repmat e indexación debería hacer el truco:

 v10=v(repmat(1:length(v),1,5))
 6
Author: Dennis Jaheruddin,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-04-23 14:28:10