我怎樣才能插入元件以陣列(A2)每第n發生在(a1)中插入項目在一個陣列中的八度每第n個位置/ MATLAB
實施例:邏輯
a1 = [1,10,2,20,3,30,4,40,5,50];
a2 = [100,200,300,400,500];
n=3 % n would be the position to place the elements found in (a2) every **nth** position in (a1).
*n is the starting position at which the array a2 is inserted into a1*
的新A1如果n = 3的插入 A2 後到它看起來像
a1 = [1,10,100,2,20,200,3,30,300,4,40,400,5,50,500];
的新A1如果n = 2的插入A2進去後看起來像
a1 = [1,100,10,2,200,20,3,300,30,4,400,40,5,500,50];
的新A1如果n = 1插入後A2到它看起來像
a1 = [100,1,10,200,2,20,300,3,30,400,4,40,500,5,50];
我試圖
a1(1:3:end,:) = a2;
,但我得到的尺寸不匹配錯誤。
請注意這只是一個例子,所以我不能只是計算一個答案我需要將數據插入到數組。 Ñ是所述陣列A2插入A1
從你的例子中,你似乎並沒有在每個'第n'位置插入'a2'的元素,而是將它們插入到每個'3rd'位置,以'n'開始。那是你想要達到的目標嗎? – beaker
@beaker在這種情況下,您是正確的 –
「在此實例中」意味着其他實例的行爲不同。除非你告訴我們所有情況下的行爲,我認爲任何人都無法幫助你。 – beaker