I have an original vector A = [0 0 0 2 5 3 6 0 0 0 9 5 6], after performing an operation on A for which I left out the zeros, I end up with a second vector B = [ 6 9 8 3 8 7 2]. Now the number of non-zero elements in A and B are equal. I want to make a third vector C that takes the shape of vector A but populated with elements from B such that C = [0 0 0 6 9 8 3 0 0 0 8 7 2].

 채택된 답변

madhan ravi
madhan ravi 2018년 10월 22일
편집: madhan ravi 2018년 10월 22일

0 개 추천

>> A = [0 0 0 2 5 3 6 0 0 0 9 5 6]
B = [ 6 9 8 3 8 7 2]
idx=(A~=0);
A(idx)=B;
C = A
A =
0 0 0 2 5 3 6 0 0 0 9 5 6
B =
6 9 8 3 8 7 2
C =
0 0 0 6 9 8 3 0 0 0 8 7 2
>>

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Aerospace Blockset에 대해 자세히 알아보기

질문:

Ev
2018년 10월 22일

편집:

2018년 10월 22일

Community Treasure Hunt

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

Start Hunting!

Translated by