How can i classify my data?

3 views (last 30 days)
Ahmet altunsu
Ahmet altunsu on 29 Jul 2019
Commented: Andrei Bobrov on 2 Aug 2019
Hi i have measurement data like below. My purpose is classify the data by first column and i want to do it with ranges. So first classification is 0<first column<0.5 and average the other columns by first range and wanna do it with 0.5 step. to be more clear for example for 0<first column<0.5 , i want to do average first column's first 3 row and avegare other column's first column's first 3 row. Sorry about my grammer and thanks already.
0.47 15.905 8.434 14.018 1010.803 1458.32 148.46
0.34 18.346 8.282 16.443 1012.711 1460.69 140.41
0.4 17.459 8.355 15.547 1012.004 1459.89 132.98
0.82 15.881 8.441 13.991 1010.783 1458.32 124.75
1.52 17.944 8.262 16.059 1012.419 1460.16 117
2.29 20.022 8.169 18.144 1014.062 1462.37 109.74
3.07 20.03 8.163 18.154 1014.074 1462.37 109.74
3.9 20.033 8.165 18.156 1014.08 1462.4 102.94
4.69 20.033 8.158 18.16 1014.087 1462.38 96.59
5.53 20.036 8.157 18.163 1014.093 1462.4 90.6
6.3 20.036 8.154 18.164 1014.098 1462.4 84.98
7.13 20.039 8.152 18.168 1014.106 1462.41 79.68
7.94 20.038 8.149 18.169 1014.11 1462.41 74.73
8.74 20.046 8.147 18.178 1014.121 1462.43 70.09
9.45 20.045 8.147 18.176 1014.123 1462.44 65.75
10.03 20.051 8.151 18.18 1014.128 1462.47 61.75
10.56 20.051 8.151 18.179 1014.13 1462.48 61.75
10.89 20.051 8.151 18.179 1014.132 1462.48 57.93
11.3 20.051 8.153 18.178 1014.133 1462.49 54.35
11.72 20.052 8.154 18.178 1014.135 1462.51 51.01
11.8 20.052 8.155 18.178 1014.135 1462.51 50.33
11.9 20.054 8.154 18.181 1014.137 1462.51 47.7
12.15 20.053 8.155 18.179 1014.138 1462.52 45.66
12.25 20.042 8.155 18.168 1014.129 1462.51 42.84

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 29 Jul 2019
Edited: Andrei Bobrov on 2 Aug 2019
a = [ 0.47 15.905 8.434 14.018 1010.803 1458.32 148.46
0.34 18.346 8.282 16.443 1012.711 1460.69 140.41
0.4 17.459 8.355 15.547 1012.004 1459.89 132.98
0.82 15.881 8.441 13.991 1010.783 1458.32 124.75
1.52 17.944 8.262 16.059 1012.419 1460.16 117
2.29 20.022 8.169 18.144 1014.062 1462.37 109.74
3.07 20.03 8.163 18.154 1014.074 1462.37 109.74
3.9 20.033 8.165 18.156 1014.08 1462.4 102.94
4.69 20.033 8.158 18.16 1014.087 1462.38 96.59
5.53 20.036 8.157 18.163 1014.093 1462.4 90.6
6.3 20.036 8.154 18.164 1014.098 1462.4 84.98
7.13 20.039 8.152 18.168 1014.106 1462.41 79.68
7.94 20.038 8.149 18.169 1014.11 1462.41 74.73
8.74 20.046 8.147 18.178 1014.121 1462.43 70.09
9.45 20.045 8.147 18.176 1014.123 1462.44 65.75
10.03 20.051 8.151 18.18 1014.128 1462.47 61.75
10.56 20.051 8.151 18.179 1014.13 1462.48 61.75
10.89 20.051 8.151 18.179 1014.132 1462.48 57.93
11.3 20.051 8.153 18.178 1014.133 1462.49 54.35
11.72 20.052 8.154 18.178 1014.135 1462.51 51.01
11.8 20.052 8.155 18.178 1014.135 1462.51 50.33
11.9 20.054 8.154 18.181 1014.137 1462.51 47.7
12.15 20.053 8.155 18.179 1014.138 1462.52 45.66
12.25 20.042 8.155 18.168 1014.129 1462.51 42.84 ];
EDIT 2
a = sortrows(a,1);% THIS is added
z = a([1,end],1)/.5;
ii = (floor(z(1)):ceil(z(2)))';
T = array2table(a);
T.(char(string('a')+(size(a,2)+1))) = discretize(a(:,1),ii*.5);
T_out = varfun(@mean,T,...
'GroupingVariables','a8','InputVariables',2:size(T,2)-1);
n = numel(ii)-1;% THIS is added
lo = ismember((1:n)',T_out.a8);% HERE fixed
Z = nan(n,width(T_out));
Z(lo,:) = T_out{:,:};
Tout_out = array2table(Z,'VariableNames',T_out.Properties.VariableNames);
  9 Comments
Ahmet altunsu
Ahmet altunsu on 2 Aug 2019
Edited: Ahmet altunsu on 2 Aug 2019
a=[
0.97 20.041 8.157 18.169 1014.076 1462.33 0.58
1.02 20.04 8.156 18.169 1014.077 1462.33 0.58
1.56 20.038 8.153 18.168 1014.079 1462.33 0.57
1.62 20.039 8.155 18.168 1014.079 1462.33 0.56
1.15 20.039 8.154 18.169 1014.078 1462.32 0.54 ]
the error is "Unable to perform assignment because the size of
the left side is 1-by-8 and the size of the right
side is 2-by-8."
Andrei Bobrov
Andrei Bobrov on 2 Aug 2019
Fixed (EDIT 2).

Sign in to comment.

More Answers (0)

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!