我有一个使用四个索引 i、j、k 和 l 创建的矩阵。我使用以下方案来创建矩阵,
for i = 1:N
for j = 1:2
for k = 1:2
for l = 1:N
Matrix(l,2(j+2*i-3)+k) = Value
end
end
end
end
当我这样做时,它会产生一个矩阵,其变化如下:
Columns
i = 1 i = 1 i = 1 i = 1 i = 2 i = 2 i = 2 i = 2 ...
j = 1 j = 1 j = 2 j = 2 j = 1 j = 1 j = 2 j = 2 ...
k = 1 k = 2 k = 1 k = 2 k = 1 k = 2 k = 1 k = 2 ...
l = 1
l = 2
.
.
.
不幸的是,我将其编入了错误的索引,需要对其进行更改。我不想改变任何计算。我需要一个将上述矩阵更改为以下内容的代码:
Columns
l = 1 l = 1 l = 2 l = 2 l = 1 l = 1 l = 2 l = 2 ...
k = 1 k = 2 k = 1 k = 2 k = 1 k = 2 k = 1 k = 2 ...
i = 1 j = 1
i = 1 j = 2
i = 2 j = 1
i = 2 j = 2
.
.
.
换句话说,一个看起来像的代码,
for i = 1:N
for j = 1:2
for k = 1:2
for l = 1:N
Matrix(New Index) = Matrix(Old Index)
end
end
end
end
我该怎么做呢?谢谢。