and i want to determine which is the most frequently
occurring "character" (similar to the "mode" of a strictly
integer array).
Is there a function that will do this? Or do i have to go
through the array and keep track of which things I have
already counted and all that business?
In article <fiq28t$6qq$1@fred.mathworks.com>,
David Doria <daviddoria@gmail.com> wrote:
>I have a cell array like
>[1] [1] [2] [a] [1] [a] [2] [a]
>and i want to determine which is the most frequently
>occurring "character" (similar to the "mode" of a strictly
>integer array).
>Is there a function that will do this?
hist() or histc(). The easiest way to convert the characters
to numbers is to add 0 to the character: e.g.,
'hello' + 0
will be a numeric array of length 5 containing the numeric codes
for each character.
--
"There are some ideas so wrong that only a very intelligent person
could believe in them." -- George Orwell
that actually might work in this case since i'll probably
have a one to one mapping from character sets to summed
ascii numbers. however, if i was not sure i would have this
one to one mapping , my original question of whether there
is some sort of function that already does this holds.
thanks,
david
roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson) wrote in
message <fiq3pf$4oc$1@canopus.cc.umanitoba.ca>...
> In article <fiq28t$6qq$1@fred.mathworks.com>,
> David Doria <daviddoria@gmail.com> wrote:
> >I have a cell array like
>
> >[1] [1] [2] [a] [1] [a] [2] [a]
>
> >and i want to determine which is the most frequently
> >occurring "character" (similar to the "mode" of a strictly
> >integer array).
>
> >Is there a function that will do this?
>
> hist() or histc(). The easiest way to convert the characters
> to numbers is to add 0 to the character: e.g.,
>
> 'hello' + 0
>
> will be a numeric array of length 5 containing the numeric
codes
> for each character.
> --
> "There are some ideas so wrong that only a very
intelligent person
> could believe in them." --
George Orwell
"David Doria" <daviddoria@gmail.com> wrote in message
<fiq5me$64a$1@fred.mathworks.com>...
> that actually might work in this case since i'll probably
> have a one to one mapping from character sets to summed
> ascii numbers. however, if i was not sure i would have this
> one to one mapping , my original question of whether there
> is some sort of function that already does this holds.
>
Can you just call two modes, one for char, once for integer?
ahh thats a good idea
I'll have to look into that code this weeeknd - i never
really followed the @ in matlab, but I haven't done my
research on it!
thanks!
"Bruno Luong" <brunoluong@yahoo.com> wrote in message
<fiq6je$k8t$1@fred.mathworks.com>...
> "David Doria" <daviddoria@gmail.com> wrote in message
> <fiq5me$64a$1@fred.mathworks.com>...
> > that actually might work in this case since i'll probably
> > have a one to one mapping from character sets to summed
> > ascii numbers. however, if i was not sure i would have this
> > one to one mapping , my original question of whether there
> > is some sort of function that already does this holds.
> >
>
> Can you just call two modes, one for char, once for integer?
>
> c={1 2 1 'a' 3 'b' 'a' 2 'a' 10};
>
> [mostc fc]=mode(double(cell2mat(c(cellfun(@ischar,c)))))
> [mosti fi]=mode(double(cell2mat(c(cellfun(@isnumeric,c)))))
>
> if fc>fi % char wins
> mostelem=char(mostc)
> else % integer wins
> mostelem=mosti
> end
>
> Bruno
>
thanks alot. the function handle @ is very easy to
understand when you read the help! haha
dave
"David Doria" <daviddoria@gmail.com> wrote in message
<fiqgul$r2o$1@fred.mathworks.com>...
> ahh thats a good idea
> I'll have to look into that code this weeeknd - i never
> really followed the @ in matlab, but I haven't done my
> research on it!
>
> thanks!
>
> "Bruno Luong" <brunoluong@yahoo.com> wrote in message
> <fiq6je$k8t$1@fred.mathworks.com>...
> > "David Doria" <daviddoria@gmail.com> wrote in message
> > <fiq5me$64a$1@fred.mathworks.com>...
> > > that actually might work in this case since i'll probably
> > > have a one to one mapping from character sets to summed
> > > ascii numbers. however, if i was not sure i would
have this
> > > one to one mapping , my original question of whether there
> > > is some sort of function that already does this holds.
> > >
> >
> > Can you just call two modes, one for char, once for integer?
> >
> > c={1 2 1 'a' 3 'b' 'a' 2 'a' 10};
> >
> > [mostc fc]=mode(double(cell2mat(c(cellfun(@ischar,c)))))
> > [mosti fi]=mode(double(cell2mat(c(cellfun(@isnumeric,c)))))
> >
> > if fc>fi % char wins
> > mostelem=char(mostc)
> > else % integer wins
> > mostelem=mosti
> > end
> >
> > Bruno
> >
>
thanks alot. the function handle @ is very easy to
understand when you read the help! haha
dave
"David Doria" <daviddoria@gmail.com> wrote in message
<fiqgul$r2o$1@fred.mathworks.com>...
> ahh thats a good idea
> I'll have to look into that code this weeeknd - i never
> really followed the @ in matlab, but I haven't done my
> research on it!
>
> thanks!
>
> "Bruno Luong" <brunoluong@yahoo.com> wrote in message
> <fiq6je$k8t$1@fred.mathworks.com>...
> > "David Doria" <daviddoria@gmail.com> wrote in message
> > <fiq5me$64a$1@fred.mathworks.com>...
> > > that actually might work in this case since i'll probably
> > > have a one to one mapping from character sets to summed
> > > ascii numbers. however, if i was not sure i would
have this
> > > one to one mapping , my original question of whether there
> > > is some sort of function that already does this holds.
> > >
> >
> > Can you just call two modes, one for char, once for integer?
> >
> > c={1 2 1 'a' 3 'b' 'a' 2 'a' 10};
> >
> > [mostc fc]=mode(double(cell2mat(c(cellfun(@ischar,c)))))
> > [mosti fi]=mode(double(cell2mat(c(cellfun(@isnumeric,c)))))
> >
> > if fc>fi % char wins
> > mostelem=char(mostc)
> > else % integer wins
> > mostelem=mosti
> > end
> >
> > Bruno
> >
>
thanks alot. the function handle @ is very easy to
understand when you read the help! haha
dave
"David Doria" <daviddoria@gmail.com> wrote in message
<fiqgul$r2o$1@fred.mathworks.com>...
> ahh thats a good idea
> I'll have to look into that code this weeeknd - i never
> really followed the @ in matlab, but I haven't done my
> research on it!
>
> thanks!
>
> "Bruno Luong" <brunoluong@yahoo.com> wrote in message
> <fiq6je$k8t$1@fred.mathworks.com>...
> > "David Doria" <daviddoria@gmail.com> wrote in message
> > <fiq5me$64a$1@fred.mathworks.com>...
> > > that actually might work in this case since i'll probably
> > > have a one to one mapping from character sets to summed
> > > ascii numbers. however, if i was not sure i would
have this
> > > one to one mapping , my original question of whether there
> > > is some sort of function that already does this holds.
> > >
> >
> > Can you just call two modes, one for char, once for integer?
> >
> > c={1 2 1 'a' 3 'b' 'a' 2 'a' 10};
> >
> > [mostc fc]=mode(double(cell2mat(c(cellfun(@ischar,c)))))
> > [mosti fi]=mode(double(cell2mat(c(cellfun(@isnumeric,c)))))
> >
> > if fc>fi % char wins
> > mostelem=char(mostc)
> > else % integer wins
> > mostelem=mosti
> > end
> >
> > Bruno
> >
>
thanks alot. the function handle @ is very easy to
understand when you read the help! haha
dave
"David Doria" <daviddoria@gmail.com> wrote in message
<fiqgul$r2o$1@fred.mathworks.com>...
> ahh thats a good idea
> I'll have to look into that code this weeeknd - i never
> really followed the @ in matlab, but I haven't done my
> research on it!
>
> thanks!
>
> "Bruno Luong" <brunoluong@yahoo.com> wrote in message
> <fiq6je$k8t$1@fred.mathworks.com>...
> > "David Doria" <daviddoria@gmail.com> wrote in message
> > <fiq5me$64a$1@fred.mathworks.com>...
> > > that actually might work in this case since i'll probably
> > > have a one to one mapping from character sets to summed
> > > ascii numbers. however, if i was not sure i would
have this
> > > one to one mapping , my original question of whether there
> > > is some sort of function that already does this holds.
> > >
> >
> > Can you just call two modes, one for char, once for integer?
> >
> > c={1 2 1 'a' 3 'b' 'a' 2 'a' 10};
> >
> > [mostc fc]=mode(double(cell2mat(c(cellfun(@ischar,c)))))
> > [mosti fi]=mode(double(cell2mat(c(cellfun(@isnumeric,c)))))
> >
> > if fc>fi % char wins
> > mostelem=char(mostc)
> > else % integer wins
> > mostelem=mosti
> > end
> >
> > Bruno
> >
>
"David Doria" <daviddoria@gmail.com> wrote in message
<fisi89$1uk$1@fred.mathworks.com>...
> thanks alot. the function handle @ is very easy to
> understand when you read the help! haha
>
> dave
>
> "David Doria" <daviddoria@gmail.com> wrote in message
> <fiqgul$r2o$1@fred.mathworks.com>...
> > ahh thats a good idea
> > I'll have to look into that code this weeeknd - i never
> > really followed the @ in matlab, but I haven't done my
> > research on it!
> >
> > thanks!
> >
> > "Bruno Luong" <brunoluong@yahoo.com> wrote in message
> > <fiq6je$k8t$1@fred.mathworks.com>...
> > > "David Doria" <daviddoria@gmail.com> wrote in message
> > > <fiq5me$64a$1@fred.mathworks.com>...
> > > > that actually might work in this case since i'll
probably
> > > > have a one to one mapping from character sets to summed
> > > > ascii numbers. however, if i was not sure i would
> have this
> > > > one to one mapping , my original question of whether
there
> > > > is some sort of function that already does this holds.
> > > >
> > >
> > > Can you just call two modes, one for char, once for
integer?
> > >
> > > c={1 2 1 'a' 3 'b' 'a' 2 'a' 10};
> > >
> > > [mostc fc]=mode(double(cell2mat(c(cellfun(@ischar,c)))))
> > > [mosti
fi]=mode(double(cell2mat(c(cellfun(@isnumeric,c)))))
> > >
> > > if fc>fi % char wins
> > > mostelem=char(mostc)
> > > else % integer wins
> > > mostelem=mosti
> > > end
> > >
> > > Bruno
> > >
> >
>
"David Doria" <daviddoria@gmail.com> wrote in message
<fisjoe$idh$1@fred.mathworks.com>...
> any idea why this got posted so many times?
>
echo of "hahha"?
Bruno
Tags for this Thread
Add a New Tag:
Separated by commas
Ex.: root locus, bode
What are tags?
A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.
Anyone can tag a thread. Tags are public and visible to everyone.
NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for
all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content.
Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available
via MATLAB Central.
Read the complete Terms prior to use.