help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding whether the element of the array is present in the other arr


From: Pantxo
Subject: Re: Finding whether the element of the array is present in the other array and finding the index value
Date: Tue, 26 May 2020 18:21:33 -0500 (CDT)

GK19 wrote
> i have 2 arrays
> p = -0.20000 1.80000
> v = 0.9000 0.30000 1.20000 1.50000 1.80000
> I have to compare both the array and finding the whether the element
> present
> in p is equal to the element present in v. It has to check each value.
> if its a success then print the value and the index along it.
> how to do it? 
> Please help
> 
> 
> 
> --
> Sent from:
> https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

Hi,

I think "ismember" is what you are looking for:

p = [-0.2 1.8 3.2];
v = [0.9 0.3 1.2 1.5 1.8 3.2];
[tf, idx] = ismember (p, v);
common_values = p(tf)
indices_in_v = idx(tf)

HTH,

Pantxo




--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html



reply via email to

[Prev in Thread] Current Thread [Next in Thread]