how to duplicate data length of a workspace ?

1 visualización (últimos 30 días)
imene. B
imene. B el 21 de Jul. de 2016
Editada: James Tursa el 21 de Jul. de 2016
hello all,
i have a data in workspace, for example a column of 1 2 3 4 , and i have an other data with a column with a N length, i want to have a new column that contain the 1 2 3 4 and repeat it till it arrive to N length, how to do that ?
thank you.

Respuesta aceptada

imene. B
imene. B el 21 de Jul. de 2016
data = evalin('base','data')
Y = evalin('base','Y')
M=length(data)/length(Y);
(assignin('base','M',M))
D=repmat(Y,M);
(assignin('base','D',D))

Más respuestas (1)

James Tursa
James Tursa el 21 de Jul. de 2016
Editada: James Tursa el 21 de Jul. de 2016
E.g., assuming N is divisible by 4:
result = repmat(column_vector,N/4,1);
If you have to cover cases where N is not divisible by 4, e.g.,
result = repmat(column_vector,ceil(N/4),1);
result = result(1:N);
or another way
result = column_vector(mod(0:N-1,4)+1);
If your column_vector is not really 4 elements but something else, simply replace 4 with numel(column_vector) in the above code.
  1 comentario
imene. B
imene. B el 21 de Jul. de 2016
thank you james, just in the moment that i figured it out :D

Iniciar sesión para comentar.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by