Assigning value to an array

조회 수: 27 (최근 30일)
Majbah
Majbah 2014년 3월 26일
댓글: Majbah 2014년 3월 26일
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
dpb
dpb 2014년 3월 26일
Do you have both index arrays initially? If so, make the intersection there and do the operation before the assignment.
Majbah
Majbah 2014년 3월 26일
Yes, I have the indices initially. If, I have multiple indices to assign to this array in this way, What can I do?
'intersect' works for two array only.

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

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 26일
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개)

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by