shift values in an array systematically
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Pegah Kassraian Fard
el 3 de Dic. de 2017
Comentada: Pegah Kassraian Fard
el 3 de Dic. de 2017
Hi
I have an array of say 1 x 320. Now after each multiple of 40, I want to include 7 times a number 11, and then continue with the next 40 entries of the original array and so on. As an illustration: array(1:40) would be as before, array(41:47) would contain 11s now, and array(48:67) would contain what was previously in array(41:60), and so on, for all multiples of 40. How can I do that most efficiently? Thanks
0 comentarios
Respuesta aceptada
Jos (10584)
el 3 de Dic. de 2017
Here is one way:
x = 1:320 ;
dp = 40 ;
v11 = repmat(11,1,7) ;
c = arrayfun(@(k) [x(k:min(k+39,end)) v11], 1:dp:numel(x), 'un',0) ;
out = cat(2, c{:})
Más respuestas (0)
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!