Is there a smart way to update the array?

1 回表示 (過去 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 Center および File ExchangeWhos についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by