# Insert new values in specific position after processing

조회 수: 11 (최근 30일)
Elysi Cochin 2023년 2월 12일
댓글: Elysi Cochin 2023년 2월 12일
I have a vector A of logical datatype size 5 x 1
A = [1 0 0 1 1 ];
Then I extracted the features where A = 1
ind1 = A(:,1) == 1;
A1 = Feat(ind1,:);
After processing I obtained a new vector
Anew = [ 1 0 1]
Now I want to insert the Anew back to A in the same position to obtain the result as
[1 0 0 0 1]
When I insert the vector back the values are not coming correctly.
Please can someone help me to insert Anew to A in the same position.
The size of vector A can vary

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

### 채택된 답변

편집: Askic V 2023년 2월 12일
In such stuations, I would keep track of indices of elements in the original vector, use find function.
A = logical([1 0 0 1 1]);
ind = find(A == 1)
ind = 1×3
1 4 5
% processing
Anew = logical([1 0 1]);
A(ind) = Anew
A = 1×5 logical array
1 0 0 0 1
If you really need to change and process the original vector, then instead of removing element in it, place Nan in its position as a placeholder.
##### 댓글 수: 3이전 댓글 1개 표시이전 댓글 1개 숨기기
편집: Askic V 2023년 2월 12일
In the following example, the result is expected:
A = [5 5 3 2 1 3 4 5 6 2 1 4 5]
A = 1×13
5 5 3 2 1 3 4 5 6 2 1 4 5
ind = find(A == 5) % keep track of the indices
ind = 1×4
1 2 8 13
% processing
%..........
A(ind) = [999.9, 99.9, 9.9, 0.99]
A = 1×13
999.9000 99.9000 3.0000 2.0000 1.0000 3.0000 4.0000 9.9000 6.0000 2.0000 1.0000 4.0000 0.9900
So the logic is good. Please post your code and an example where elements are placed in the wrng positions.
Elysi Cochin 2023년 2월 12일
Now its working. Thank you

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

### 추가 답변 (1개)

Voss 2023년 2월 12일
A(ind1) = Anew;

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

### 카테고리

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