Replace an element in a vector with another element.

조회 수: 2 (최근 30일)
kumar vivek
kumar vivek 2015년 11월 11일
댓글: Mohammad Abouali 2015년 11월 16일
I want to replace the elements of a vector with an element from other vector. But the real glitch here is that i just want 4 values from that vector to be activated and replaced.
So the code goes like this:
g=[1 2 3 4 5 6 7 8 9];
u=[1 1 3 5 4 3 7 8 9];
gout =g;
active_g = [2 3 5 6];
active_u = [2 3 5 6];
U = (g(active_g)>u(active_u))
gout(U) = u(U);
gout(~U) = g(~U);
Now the output should be gout = [1 1 3 4 4 3 7 8 9] But due to U becoming a 1*4 vector.. its not updating elements after that. Kindly suggest a way around. I just need to update the active elements and send it to other function as input but at the same time i need the complete g to evaluate another function.
So its like input g -> function(g,l) -> function (g_updated).

채택된 답변

Mohammad Abouali
Mohammad Abouali 2015년 11월 11일
편집: Mohammad Abouali 2015년 11월 11일
g=[1 2 3 4 5 6 7 8 9];
u=[1 1 3 5 4 3 7 8 9];
gout=min([g;u])
gout =
       1     1     3     4     4     3     7     8     9
  댓글 수: 3
kumar vivek
kumar vivek 2015년 11월 16일
Thanks Mohammad Abouali for the answer. It really solved my problem :)
Mohammad Abouali
Mohammad Abouali 2015년 11월 16일
you are welcome

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 App Building에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by