Adding 3 numbers out of 5

3 次查看(过去 30 天)
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
Sarah, you could use
data = [A B C D E];
datasum = sum(combnk(data,3),2);
  3 个评论
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 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by