你的問題是一個非常具體的問題。我不明白這對除了你自己以外的人有什麼用處。 沒有「單線解決方案」。 有很多方法可以解決索引問題,我喜歡用標索引時可能:
Ncolumns = size(Matrix,1);
Nblocks = floor(Ncolumns/4); %number of 4-line blocks (excluding the last block if it is not a full 4-lines)
IndexVector = (1:3)'*ones(1,3) + ones(3,1)*(0:2) * Ncolumns; %this gives 3 lines as specified.
IndexVector = [IndexVector(:); 4]; %this adds the first element of 4th line, as spec.
IndexVector = IndexVector*ones(1,Nblocks)+ones(10,1)*(0:Nblocks-1)*4; %this repeats the above for rest of blocks.
IndexVector = IndexVector(:)'; %make row vector
vector=Matrix(IndexVector);
if mod(Ncolumns,4) %this deals with the last partial block
subMat=Matrix(Nblocks*4+1:end,1:3);
vector=[vector subMat(:)'];
end
你覺得重塑時,與一個for循環?無論如何,你應該展示你迄今爲止的嘗試。這樣做我和你將有更好的機會在這裏獲得幫助。 – patrik
你的描述說你以某種方式重新排列元素,但矩陣和向量包含不同的元素。 – Daniel
我嘗試重塑矩陣,但它不起作用。 – Dani