matlab矩阵问题 。

8 visualizaciones (últimos 30 días)
kiritw
kiritw el 24 de Nov. de 2022
Respondida: kafabem el 24 de Nov. de 2022
已知一组数组A=[2 4 6 2 1 4 5 6 6 2 1 4 6 4 5 ],我想前3个数一组,往后5个数一组,再往后3个数一组,最后4个数一组,从四个大组中都随机选一个数组成新的一行,由于全排列共有3*5*3*4=180行
求算法,谢谢

Respuesta aceptada

kafabem
kafabem el 24 de Nov. de 2022
A=[2 4 6 2 1 4 5 6 6 2 1 4 6 4 5 ];
%,我想前3个数一组,往后5个数一组,再往后3个数一组,最后4个数一组
a1=[2 4 6];
a2=[2 1 4 5 6];
a3=[6 2 1];
a4=[4 6 4 5];
j=1;
B=ones(180,4);
for ia=1:length(a1)
for ib=1:length(a2)
for ic=1:length(a3)
for id=1:length(a4)
B(j,:)=[a1(ia),a2(ib),a3(ic),a4(id)];
j=j+1;
end
end
end
end
B是180*4的矩阵

Más respuestas (0)

Categorías

Más información sobre MATLAB 快速入门 en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!