Effacer les filtres
Effacer les filtres

Adding 3 numbers out of 5

2 vues (au cours des 30 derniers jours)
MatlabGirl
MatlabGirl le 27 Mar 2014
Commenté : MatlabGirl le 27 Mar 2014
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.

Réponse acceptée

Mischa Kim
Mischa Kim le 27 Mar 2014
Modifié(e) : Mischa Kim le 27 Mar 2014
Sarah, you could use
data = [A B C D E];
datasum = sum(combnk(data,3),2);
  3 commentaires
Mischa Kim
Mischa Kim le 27 Mar 2014
Modifié(e) : Mischa Kim le 27 Mar 2014
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 le 27 Mar 2014
Thanks a lot! I can't thank you enough!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by