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:
Easy way to classified data

Subject: Easy way to classified data

From: edward kabanyas

Date: 17 Jun, 2010 12:30:23

Message: 1 of 5

Hi all,

I am classifying the data as follow:

A1 = data(data(:,1)>0.0 & data(:,1)<= 0.2,:);
A2 = data(data(:,1)>0.2 & data(:,1)<= 0.4,:);
A3 = data(data(:,1)>0.4 & data(:,1)<= 0.6,:);
A4 = data(data(:,1)>0.6 & data(:,1)<= 0.8,:);
A5 = data(data(:,1)>0.8 & data(:,1)<= 1.0,:);
A6 = data(data(:,1)>1.0 & data(:,1)<= 1.2,:);

However, if the data category is large, conventional classification as in the above method will take long time to write the code. Do you have any simple way instead of the above method?

Thanks for help.

Edward

Subject: Easy way to classified data

From: us

Date: 17 Jun, 2010 12:44:04

Message: 2 of 5

"edward kabanyas" <djuky_hmi@yahoo.com> wrote in message <hvd4gv$id0$1@fred.mathworks.com>...
> Hi all,
>
> I am classifying the data as follow:
>
> A1 = data(data(:,1)>0.0 & data(:,1)<= 0.2,:);
> A2 = data(data(:,1)>0.2 & data(:,1)<= 0.4,:);
> A3 = data(data(:,1)>0.4 & data(:,1)<= 0.6,:);
> A4 = data(data(:,1)>0.6 & data(:,1)<= 0.8,:);
> A5 = data(data(:,1)>0.8 & data(:,1)<= 1.0,:);
> A6 = data(data(:,1)>1.0 & data(:,1)<= 1.2,:);
>
> However, if the data category is large, conventional classification as in the above method will take long time to write the code. Do you have any simple way instead of the above method?
>
> Thanks for help.
>
> Edward

one of the many solutions

% the data
% - intervals
     iv=0:.2:1; % <- your stuff...
     v=rand(1,10); % <- your data...
% the engine
     [ix,ix]=histc(v,iv);
     r=arrayfun(@(x) v(ix==x),1:max(ix),'uni',false);
% the result
     disp(r{1}); % <- data in first int...
%{
% not shown since based on RAND...
%}

us

Subject: Easy way to classified data

From: edward kabanyas

Date: 17 Jun, 2010 13:17:05

Message: 3 of 5

Hi Us,

Thanks for your reply.

I think your solution is working for the data containing one column only. Could you show me how to implement if my data more than one column? For example, the data are:

0.51 0.81
1.16 0.95
4.03 1.23
2.85 0.94
1.18 0.90
1.42 0.90
0.78 0.89
0.55 0.80
0.28 0.81
0.22 0.80
0.16 0.72

A1 = data(data(:,1)>0.0 & data(:,1)<= 0.2,:);
A2 = data(data(:,1)>0.2 & data(:,1)<= 0.4,:);

Classification is based on column 1 (data(:,1)), but I need also the second column. Hence A1 is also two column as in data file.

Thanks again, Edward.

Subject: Easy way to classified data

From: us

Date: 17 Jun, 2010 13:26:05

Message: 4 of 5

"edward kabanyas" <djuky_hmi@yahoo.com> wrote in message <hvd78h$cs7$1@fred.mathworks.com>...
> Hi Us,
>
> Thanks for your reply.
>
> I think your solution is working for the data containing one column only. Could you show me how to implement if my data more than one column? For example, the data are:
>
> 0.51 0.81
> 1.16 0.95
> 4.03 1.23
> 2.85 0.94
> 1.18 0.90
> 1.42 0.90
> 0.78 0.89
> 0.55 0.80
> 0.28 0.81
> 0.22 0.80
> 0.16 0.72
>
> A1 = data(data(:,1)>0.0 & data(:,1)<= 0.2,:);
> A2 = data(data(:,1)>0.2 & data(:,1)<= 0.4,:);
>
> Classification is based on column 1 (data(:,1)), but I need also the second column. Hence A1 is also two column as in data file.
>
> Thanks again, Edward.

well...
one of the solutions

     v=rand(10,2); % <- now a two col(!) vec...
     iv=0:.2:1;
     [ix,ix]=histc(v(:,1),iv);
     r=arrayfun(@(x) v(ix==x,:),1:max(ix),'uni',false);
     r{:}

us

Subject: Easy way to classified data

From: edward kabanyas

Date: 17 Jun, 2010 13:36:07

Message: 5 of 5

Thanks so much Us, it's perfect..

Tags for 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