What does ix=ismembe​r(vars,["s​tate","sou​rce"])| contains(vars,["lat", "lon", "timestamp", "damage", "event"]); do?

2 views (last 30 days)
What does the code line
ix=ismember(vars,["state","source"])| contains(vars,["lat", "lon", "timestamp", "damage", "event"]);
As far as I understand, the ix of each row is 1 when "state" and "source" or ["lat", "lon", "timestamp", "damage", "event"] are in the vars-string. Is this correct?
  1 Comment
Stephen23
Stephen23 on 13 Jan 2022
Where any element of vars is either:
  • equal to "state"
  • equal to "source"
  • contains "lat"
  • contains "lon"
  • contains "timestamp"
  • etc.
the corresponding element of the output IX will be TRUE, otherwise the element will be FALSE.

Sign in to comment.

Accepted Answer

KSSV
KSSV on 13 Jan 2022
idx1=ismember(vars,["state","source"]) ; % gives logical indexing where state, source are presnt in vars
idx2 = contains(vars,["lat", "lon", "timestamp", "damage", "event"]); % gives logical indices where loat, lon etc are present in vats
ix = idx1 | idx2 ; % gives logical indexing of or of the above indices
  6 Comments
Stephen23
Stephen23 on 13 Jan 2022
"Why are there two functions, which do the same thing?"
They don't do the same thing.

Sign in to comment.

More Answers (0)

Categories

Find more on Function Creation in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!