Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Sort the data

Subject: Sort the data

From: Vladimir V Bogachuk

Date: 24 Apr, 2012 02:03:10

Message: 1 of 3

Hello,
  I can't find a command in MATLAB to go through the data points I have below and count how many of the same strings are there. For example there are 5 data strings that represent 13:09, 1 string that represent 13:11 and so on. What I need the command to do is recognize that there are five 13:09 data points, one 13:11 data point and so on.


13:09
13:09
13:09
13:09
13:09
13:11
13:23
13:23
13:23
13:30
13:30
15:44
15:44
15:44
15:44
15:44

Subject: Sort the data

From: Roger Stafford

Date: 24 Apr, 2012 02:19:08

Message: 2 of 3

"Vladimir V Bogachuk" wrote in message <jn51kt$6oo$1@newscl01ah.mathworks.com>...
> Hello,
> I can't find a command in MATLAB to go through the data points I have below and count how many of the same strings are there. For example there are 5 data strings that represent 13:09, 1 string that represent 13:11 and so on. What I need the command to do is recognize that there are five 13:09 data points, one 13:11 data point and so on.
>
>
> 13:09
> 13:09
> 13:09
> 13:09
> 13:09
> 13:11
> 13:23
> 13:23
> 13:23
> 13:30
> 13:30
> 15:44
> 15:44
> 15:44
> 15:44
> 15:44
- - - - - - - - -
  You have referred to these quantities as "strings". What do you mean by that? If they are actually decimal fractions, use 'unique' on them first, then 'histc'.

  If these numbers were arrived at by way of computations, don't be surprised if some of them are different even though their display shows the same value.

Roger Stafford

Subject: Sort the data

From: Bruno Luong

Date: 24 Apr, 2012 06:28:09

Message: 3 of 3

s = {'13:09'
'13:09'
'13:09'
'13:09'
'13:09'
'13:11'
'13:23'
'13:23'
'13:23'
'13:30'
'13:30'
'15:44'
'15:44'
'15:44'
'15:44'
'15:44'}

[su I J]=unique(s);
Count=accumarray(J,1);

arg=[su num2cell(Count)]';
fprintf('(%s) -> %d times\n',arg{:})

% Bruno

Tags for this Thread

No tags are associated with this thread.

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.

Contact us