help-octave
[Top][All Lists]
Advanced

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

Re: Find egual number


From: Vic Norton
Subject: Re: Find egual number
Date: Tue, 12 Feb 2019 15:00:19 -0500

> On Feb 12, 2019, at 7:07 AM, LucaLuca <address@hidden> 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 via email to

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