Split Number into digits adding up to it.
Mostra commenti meno recenti
I need to split a number into smaller integers that add up to it.
So 4 -> [0,4],[1,3],[2,2],[3,1],[4,0]
6 -> [0,6],[1,5],[2,4],[3,3]...
I know this can be done with for loops but wanted to see if there is another way.
Risposta accettata
Più risposte (1)
KSSV
il 10 Set 2020
n = 4 ;
[X,Y] = meshgrid(0:n,0:n) ;
thesum = X+Y ;
idx = thesum==n ;
iwant = [X(idx) Y(idx)]
n = 6 ;
[X,Y] = meshgrid(0:n,0:n) ;
thesum = X+Y ;
idx = thesum==n ;
iwant = [X(idx) Y(idx)]
Categorie
Scopri di più su App Building in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!