|
楼主 |
发表于 2007-11-30 10:40
|
显示全部楼层
请问donkeyxu,如果我的数组变为5个数组,比如A=[36,40,45,46];B=[40,48,52,36]
C=[37,41,47,45];D=[43,44,45,38],E=[43,46,45]
我修改了一下程序,运行的结果不对,很着急!请你帮忙看一下,谢谢了
function haha
A=[36,40,45,46];B=[40,48,52,36];C=[37,41,47,45];D=[43,44,45,38];E=[43,46,45]
[x,y,z,w,v]=nmeshgrid(A,B,C,D,E);
x=x(:)';y=y(:)';z=z(:)';w=w(:)';v=v(:)';
U=[x;y;z;w;v];
K=var(U);
[T,R]=sort(K);
disp('the fist 3 smaller answer is:');
disp(num2str(T(1:3)'));
disp('and the elements is:');
disp('A B C D E')
disp(num2str(U(:,R(1:3))'));
function [xx1,xx2,xx3,xx4,xx5]=nmeshgrid(x1,x2,x3,x4,X5)
nx1 = numel(x1); nx2 = numel(x2); nx3 = numel(x3);nx4 = numel(x4);nx5 = numel(x5);
xx1 = reshape(full(x1(:)),[1 nx1 1 1 1]);
xx2 = reshape(full(x2(:)),[nx2 1 1 1 1]);
xx3 = reshape(full(x3(:)),[1 1 1 nx3 1]);
xx4 = reshape(full(x4(:)),[1 1 nx4 1 1]);
xx5 = reshape(full(x5(:)),[1 nx5 1 1 1]);
xx1 = xx1(ones(nx2,1),:,ones(nx5,1),ones(nx4,1),ones(nx3,1));
xx2 = xx2(:,ones(1,nx1),ones(nx5,1),ones(nx4,1),ones(nx3,1));
xx3 = xx3(ones(nx2,1),ones(nx1,1),ones(nx4,1),:,ones(nx5,1));
xx4 = xx4(ones(nx2,1),ones(nx1,1),:,ones(nx3,1),ones(nx5,1));
xx5 = xx5(ones(nx1,1),:,ones(nx4,1),:,ones(nx3,1),ones(nx2,1),); |
|