Assigning value to an array
27 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Majbah
am 26 Mär. 2014
Kommentiert: Majbah
am 26 Mär. 2014
Hello,
I want to assign value to an array. For example:
A=[0 0 0 0 0 0 0 0 0 0 0 0];
Value to Assign: A(1 2 11 12)=30;
After that, A=[30 30 0 0 0 0 0 0 0 0 0 0 30 30]
Now, I wanna assign the value A(2 10 12)=20 to the same array. But, value of the new array will be the sum of previous if the index matches.
Like: A(2)=30+20
But, A(10)=20
2 Kommentare
dpb
am 26 Mär. 2014
Do you have both index arrays initially? If so, make the intersection there and do the operation before the assignment.
Akzeptierte Antwort
Azzi Abdelmalek
am 26 Mär. 2014
A=[0 0 0 0 0 0 0 0 0 0 0 0];
A([1 2 11 12])=30
A([2 10 12])=A([2 10 12])+20
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrices and Arrays finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!