Hello,
Is is possible to use nchoosek in such a way that will keep information for more than one column vector? For example, I have a 33x3 matrix and I'd like to find all possible combinations of trios for the first column, then run calculations on the data from the other two columns associated with each member of the trio from the first column.
Thank you so much in advance for your help!

 채택된 답변

Stephen23
Stephen23 2020년 8월 25일

0 개 추천

Simply generate a matrix of indices:
idx = nchoosek(1:33,3);
and then for each row in that matrix perform your calculations, where M is your matrix:
for k = 1:size(idx,1)
ix = idx(k,:);
v1 = M(ix,1); % column 1
v2 = M(ix,2); % column 2
v3 = M(ix,3); % column 3
... do whatever with those vectors
end

댓글 수: 1

Valeria Villegas-Medina
Valeria Villegas-Medina 2020년 8월 26일
편집: Valeria Villegas-Medina 2020년 8월 26일
Thank you so much! This is exactly what I was thinking but I'm relatively new to coding and couldn't figure out the implementation. Do you happen to have a recommended tutorial channel?

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by