three variable together in one loop in different size

조회 수: 1 (최근 30일)
mohammed hussein
mohammed hussein 2017년 11월 14일
댓글: mohammed hussein 2017년 11월 15일
Hi every one i would like to have three variable working in loop one working alone and another working together in different size. for example
clear all
clc
AA=[1 2 3];
BB=[4 5 6];
CC=[7 8 9 10 11 12 13 14 15];
for ii=1:1:length(AA)
for jj=1:1:length(BB)& kk=1:1:length(CC)
A=AA(ii);
B=BB(jj);
C=CC(kk);
x=[A,B,C]
end
end the results has to be like in loop
X=[1 4 7 8 9]
X=[1 5 10 11 12]
X=[1 6 13 14 15]
X=[2 4 7 8 9]
X=[2 5 10 11 12]
X=[2 6 13 14 15]
X=[3 4 7 8 9]
X=[3 5 10 11 12]
X=[3 6 13 14 15]
thank you very much

채택된 답변

Andrei Bobrov
Andrei Bobrov 2017년 11월 14일
편집: Andrei Bobrov 2017년 11월 15일
n = numel(AA);
abc = [AA(:), BB(:), reshape(CC,n,[])'];
ii = fullfact([1 1]*n);
X = abc(bsxfun(@plus, ii(:,[2 ones(1,n+1)]), n*(0:n+1)));
  댓글 수: 5
Andrei Bobrov
Andrei Bobrov 2017년 11월 15일
I'm corrected my code.
mohammed hussein
mohammed hussein 2017년 11월 15일
thank you very much for your help

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by