フィルターのクリア

How can i see if the value occurs in an array for the first time?

1 回表示 (過去 30 日間)
Philipp Mueller
Philipp Mueller 2020 年 5 月 25 日
コメント済み: Tommy 2020 年 5 月 26 日
I have an array called loadp (50*1 double). I would like to see if the value occurs in the respective cell (loop) for the first time. If so, something should be executed. if the value has already occurred in the previous runs, the value should ignored.
for i=1:numRows;
%tmp = regexp(my_strings(i),'(?<=_l)\d+','match','once');
%loadp(i,1) = str2double(tmp)
condition=any(diff(sort(loadp(i,1))) == 0)
if condition==0
%do something
sadasd=2313
else
%do nothing
ssd=213123
end
end
  3 件のコメント
Philipp Mueller
Philipp Mueller 2020 年 5 月 25 日
It works! Thank you Tommy :)
Tommy
Tommy 2020 年 5 月 26 日
Fantastic, happy to help!
(moved to an answer)

サインインしてコメントする。

採用された回答

Tommy
Tommy 2020 年 5 月 26 日
Try one of these.
condition = ~ismember(loadp(i),loadp(1:i-1));
% or
condition = find(loadp==loadp(i),1) == i;
They should both check if i is the first index in loadp which contains loadp(i). I'm not sure which is better, or if some other way would beat both.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrices and Arrays についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by