Hi,
I am trying to do a code for channel interference. I figured out everything else but I'm stuck at a few points.
I have 5 numbers stored under different names, A,B,C,D,E.
I want to take three at a time and add them together for example: A+B+C. I want matlab to do all the combinations. Is that possible? can you tell me how?
Thank you.

 채택된 답변

Mischa Kim
Mischa Kim 2014년 3월 27일
편집: Mischa Kim 2014년 3월 27일

0 개 추천

Sarah, you could use
data = [A B C D E];
datasum = sum(combnk(data,3),2);

댓글 수: 3

MatlabGirl
MatlabGirl 2014년 3월 27일
Man! This is awesome! Thank you thank you thank you!
1) Is there another function for subtraction too. A-B-C (for the different combination) 2) What about a mix of sum and add? like A-B+C.
Thank a lot.
Mischa Kim
Mischa Kim 2014년 3월 27일
편집: Mischa Kim 2014년 3월 27일
Sure.
datadif = sum(combnk(data,3)*[1 -1 -1]',2)
With the column vector, e.g. [1 -1 -1]', you can control the signs.
MatlabGirl
MatlabGirl 2014년 3월 27일
Thanks a lot! I can't thank you enough!

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

추가 답변 (0개)

카테고리

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

태그

질문:

2014년 3월 27일

댓글:

2014년 3월 27일

Community Treasure Hunt

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

Start Hunting!

Translated by