multiplying all the components of rand

조회 수: 5 (최근 30일)
Young Chan Jung
Young Chan Jung 2019년 6월 5일
편집: Matt J 2019년 6월 5일
Hello, this is not really about rand, but since I am using rand...
For example, I want to have 3 sets of 3 different numbers. say A,B,C ; D,E,F ; G,H,I
I want to multiply components from each sets, making the total of final numbers 27. That is, 3*3*3 = 27
The numbers will be A*D*G, A*D*H, A*D*I, A*E*G, ... C*F*G, C*F*H, C*F*I.
obviously it was stupid of me to use the matrix... which will not work.
I also want this to be a array, not a matrix... or 1x27 matrix. not 3x9.
Please help me

채택된 답변

Matt J
Matt J 2019년 6월 5일
편집: Matt J 2019년 6월 5일
[x,y,z]=ndgrid( [G,H,I] , [D,E,F], [A,B,C]);
result=reshape(x.*y.*z,[],1)
  댓글 수: 1
Matt J
Matt J 2019년 6월 5일
Or, in R2016b and higher,
x=[G;H;I];
y=[D,E,F];
z=cat(3,A,B,C);
result=reshape(x.*y.*z,[],1)

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

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by