shift values in an array systematically

2 次查看(过去 30 天)
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

采纳的回答

Jos (10584)
Jos (10584) 2017-12-3
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{:})

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by