I want to check that the Value of one array exist in another array, using function ?

1 回表示 (過去 30 日間)
Aqeel Awan
Aqeel Awan 2021 年 7 月 7 日
コメント済み: Johannes Hougaard 2021 年 7 月 7 日
RemainingSensor=[1 2 4];
Cover=[1 3];
[m,n]=size(RemainingSensor);
for i=1:m
for j=1:n
r=RemainingSensor(i,j);
a=funcCover(r);
display(a);
end
end
function c= funcCover(v)
[s,t]=size(Cover);
for i1=1:s
for j1=1:t
k=Cover(i1,j1);
if k==v
c=k;
end
end
end
end
first array is "RemainingSensor" and wants to check that the of this sensor existe in other array that is "Cover", how it is possible?

回答 (1 件)

Johannes Hougaard
Johannes Hougaard 2021 年 7 月 7 日
It is possible using the function ismember
RemainingSensor=[1 2 4];
Cover=[1 3];
validsensors = ismember(RemainingSensor,Cover);
  4 件のコメント
Aqeel Awan
Aqeel Awan 2021 年 7 月 7 日
Yeah, i know but I want to do this with above scenario, that i've uploaded
Johannes Hougaard
Johannes Hougaard 2021 年 7 月 7 日
Then I'd just use funcCover as a function calling ismember.
Regardless of what you do you'll have to have two inputs to your function, as your variable 'Cover' is never sent to your function funcCover as long as it only have one input.
RemainingSensor=[1 2 4];
Cover=[1 3];
[m,n]=size(RemainingSensor);
for i=1:m
for j=1:n
r=RemainingSensor(i,j);
a=funcCover(r,Cover);
display(a);
end
end
function c= funcCover(v,W)
if ismember(v,W)
c = v;
else
c = 0;
end
end

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

カテゴリ

Help Center および File ExchangeOperators and Elementary Operations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by