필터 지우기
필터 지우기

Is there a smart way to update the array?

조회 수: 3 (최근 30일)
Niraj
Niraj 2012년 11월 25일
I am trying to update my array.i have an array ids which needs to be updated,whenever there is a new member(which is not present already in ids).Currently, i am using:
end
test = ismember(id_final,ids);%id_final is a temporary array
for k = 1:size(test,2)
if test(k) ==0
ids =cat(2,ids,id_final(k));
end
end
Is there some smart way to do this?
Please reply.

채택된 답변

Walter Roberson
Walter Roberson 2012년 11월 25일
test = ismember(id_final,ids);%id_final is a temporary array
ids = [ids id_final(~test)];
Note: if the order of the ids is not important, just use
ids = union(ids, id_final);
  댓글 수: 1
Niraj
Niraj 2012년 11월 26일
편집: Niraj 2012년 11월 26일
Thanks..it worked. :) Could you please tell me 1 small thing about answering in Mathworks! How did you add the "Accept this answer" button? I also want to add this button when reply to someone's question.
Thanks

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by