Find egual number

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Find egual number

LucaLuca
f=[1   2   3   4   4   7   7   6   8   5]

it's possible to find >1 egual element? i want to know this position

f(4)=4    f(5)=4

f(6)=7  f(7)=7

Ans=4,5
       6,7





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


Reply | Threaded
Open this post in threaded view
|

Re: Find egual number

Przemek Klosowski-7
On 2/9/19 5:58 AM, LucaLuca wrote:

> f=[1   2   3   4   4   7   7   6   8   5]
>
> it's possible to find >1 egual element? i want to know this position
>
> f(4)=4    f(5)=4
>
> f(6)=7  f(7)=7
>
> Ans=4,5
>         6,7

I am genuinely curious---there's what looks like to be a group of
Italian gentlemen:

[hidden email]

[hidden email]

[hidden email]

that regularly ask about Octave problems that, to me, share some common
characteristics, in that they explore the intricacies of syntax, in ways
that don't seem to be connected to actual practical problems. To me, it
looks like either someone's exploration of intricacies of Matlab, or a
series of homework etudes. It actually occurred to me that it could be a
Google algorithm similar to Alpha Zero
http://science.sciencemag.org/content/362/6419/1140 , trying to learn
mathematical computing :), especially since when I tried to answer one
of them (the last one) directly the email address bounced.

But, hey, let's play along. I am not sure that I understand the problem
as stated above but maybe something along the lines of

k=1:length(f)

find(f(k)==k)

or

find(f(k)!=k)

would be a solution.




Reply | Threaded
Open this post in threaded view
|

Re: Find egual number

LucaLuca
hi,
i'm subscrive mailing list.., now i can reveive your email

about you solution is not correct because if i change element in array

Example:

f=[14  54  54  65   78  67 78 67 67 78 67]

k=1:length(f)

find(f(k)==k)

ans = [](1x0) and it's not correct because you have set  a wrong loop

but never mind…



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


Reply | Threaded
Open this post in threaded view
|

Re: Find egual number

vicnorton

> On Feb 12, 2019, at 7:07 AM, LucaLuca <[hidden email]> wrote:
>
> hi,
> i'm subscrive mailing list.., now i can reveive your email
>
> about you solution is not correct because if i change element in array
>
> Example:
>
> f=[14  54  54  65   78  67 78 67 67 78 67]
>
> k=1:length(f)
>
> find(f(k)==k)
>
> ans = [](1x0) and it's not correct because you have set  a wrong loop
>
> but never mind…
>
>
>
> --
> Sent from: http://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

Try this:

f = [14  54  54  65  78  67 78 67 67 78 67];
n = length(f);
fu = unique(f);    % numbers in f in increasing order
m = length(fu);
fc = zeros(1, m);  % to count how many times each number occurs
for i = 1 : m
  fc(i) = sum(f == fu(i) * ones(1, n));
end
%{
fu =
   14   54   65   67   78     % numbers in f
fc =
    1    2    1    4    3     % number of occurences
%}

Good luck,

Vic



Reply | Threaded
Open this post in threaded view
|

Re: Find egual number

LucaLuca