Creating pairs of vector elements

15 ビュー (過去 30 日間)
N S
N S 2013 年 8 月 26 日
I have 3 vectors, each containing 9 elements. I want to create all the possible pairs (729) of the vector elements in a random order. What would be an efficient way to do it?
Thanks a million! N.

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2013 年 8 月 26 日
編集済み: Azzi Abdelmalek 2013 年 8 月 26 日
% Example
a=randi(9,9,1);
b=randi(9,9,1);
c=randi(9,9,1);
%-----------------------------------
[ii2,jj2]=ndgrid(a,b);
[ii3,jj3]=ndgrid(1:numel(ii2),c);
v2=[a(ii2(:)) b(jj2(:))];
v3=[v2(ii3(:),:) c(jj3(:))];
n=size(v3,1);
v3=v3(randperm(n),:)

Andrei Bobrov
Andrei Bobrov 2013 年 8 月 26 日
a = (1:9)';
b = a;
c = a;
[ii,jj,k] = ndgrid(a,b,c);
out = [ii(:),jj(:),k(:)];

カテゴリ

Help Center および File ExchangeLinear Model Identification についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by