three variable together in one loop in different size

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

 Respuesta aceptada

Andrei Bobrov
Andrei Bobrov el 14 de Nov. de 2017
Editada: Andrei Bobrov el 15 de Nov. de 2017
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 comentarios

mohammed hussein
mohammed hussein el 14 de Nov. de 2017
Editada: mohammed hussein el 14 de Nov. de 2017
thank you for your answer . i used this cod but it gives me this error Error using + Matrix dimensions must agree.
Error X = abs(ii(:,[2 ones(1,n+1)]) + n*(0:n+1))
I am fixed my typo.
thank you very much for helping , i still have problem . i used AA=[1 2 3]; BB=[4 5 6]; CC=[7 8 9 10 11 12 13 14 15]; n = numel(AA); abc = [AA(:), BB(:), reshape(CC,n,[])']; ii = fullfact([1 1]*n); X = abc(ii(:,[2 ones(1,n+1)]) + n*(0:n+1));
it gives me this error
Error using + Matrix dimensions must agree.
Error in test (line 9)
X = abc(ii(:,[2 ones(1,n+1)]) + n*(0:n+1));
I'm corrected my code.
thank you very much for your help

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with Phased Array System Toolbox en Centro de ayuda y File Exchange.

Preguntada:

el 14 de Nov. de 2017

Comentada:

el 15 de Nov. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by