shift values in an array systematically
2 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Pegah Kassraian Fard
il 3 Dic 2017
Commentato: Pegah Kassraian Fard
il 3 Dic 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 Commenti
Risposta accettata
Jos (10584)
il 3 Dic 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{:})
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Matrices and Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!