Hello everyone. A = [2 3 4]. I am trying to generate these 2 combinations:
  1. 22, 23 ,24 ,32 ,33 ,34, 42 ,43 ,44 (order matters so 23 not equal to 32 so nchoosek(A,2) does not work)
  2. 222, 233, 232, 234, 243, 333, 322, 323, 344, 343 , 324,342, 422, 424, 433 ,434 , 432, 423, 444. perms(A) does not do the job here because it is without replacement.
how can I do these?

 채택된 답변

Bruno Luong
Bruno Luong 2018년 11월 13일
편집: Bruno Luong 2018년 11월 13일

1 개 추천

A = [2 3 4]
[A1,A2] = ndgrid(A);
arrayfun(@(k) polyval([A2(k),A1(k)],10), 1:numel(A1))
[A1,A2,A3] = ndgrid(A);
arrayfun(@(k) polyval([A3(k),A2(k),A1(k)],10), 1:numel(A1))

댓글 수: 3

as
as 2018년 11월 15일
thank you! ..i should have put in the spaces becasue what is expcted are 2 matrices. with combinations. maybe ill just num2str and str2num the amswer. thanks.
Bruno Luong
Bruno Luong 2018년 11월 15일
편집: Bruno Luong 2018년 11월 15일
Keep telling you guys of putting more care on your question.
If you want a space then put a space.[2 2 3] is not 223.
A = [2 3 4]
[A1,A2,A3] = ndgrid(A);
[A3(:),A2(:),A1(:)]
as
as 2018년 11월 15일
thank you Bruno! I was able to modidy your code to genrate other combinations as well.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

as
2018년 11월 13일

댓글:

as
2018년 11월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by