matlab矩阵问题 。
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
已知一组数组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行
求算法,谢谢
0 commentaires
Réponse acceptée
kafabem
le 24 Nov 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的矩阵
0 commentaires
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!