Subdivide group of data

조회 수: 1 (최근 30일)
Valeria Lorenzoni
Valeria Lorenzoni 2018년 5월 8일
댓글: Razvan Carbunescu 2018년 5월 9일
I am having trouble subdiving into sub-groups my data. The first thing I was trying to do is selecting group of data every 30 degrees from 0 to 360. It makes 12 groups of data. The secong thing I would like to do is from this group of data do another selection. For each 30 degrees I would like to divide into 5 groups. Thus have 12 Groups of data and from each group have 5 sub groups. I would like to do, for every 30 degrees residual groups (azimuth), the median of the residuals every 50m (epicenter distance). For example for the group of data with residuals that are between 0-30 degrees I would like to do the median of these residuals with epicentral distance from 0-50, 50-100,..., 250-300. This is the code I tried but it says that the indexe exceeds the matrix, I tried other things but have the same problem:
%dividing for epicenter distance from 0 to 300m every 50m
N_pieces3=6;
cheese_angle3=300/N_pieces3;
%diving for azimuth from 0 to 360
N_pieces=12;
cheese_angle=360/N_pieces;
%select groups of residuals every 30 degrees and epicentral distance every 30 degrees
for nps=1:N_pieces
resp1=resp(azmp1>=cheese_angle*(nps-1) & azmp1<=cheese_angle*nps);
depip1=depip(azmp1>=cheese_angle*(nps-1) & azmp1<=cheese_angle*nps);
%divind into 6 groups from the previous residual groups depending on the epicentral distance and compute its mean every 50m
for c=1:N_pieces3
resp3=resp1(depip>=cheese_angle3*(c-1) & depip<=cheese_angle3*c);
depip3=depip1(depip>=cheese_angle3*(c-1) & depip<=cheese_angle3*c );
angle3(c)=cheese_angle3*((c-1)+.5); %for plotting: the point must be at the center
Med(nps)=median(resp3)-medAs;
end
angle2=cheese_angle3*((nps-1)+.5); %for plotting: the point must be in the middle
end
At the end I would like to do a 3D plotting with the residuals median depending on the azimuth and the epicentral distance. If possible a 3D polar scatter. Thank you.

채택된 답변

Razvan Carbunescu
Razvan Carbunescu 2018년 5월 8일
If using R2018a you can compute the data easier by using groupsummary.
T = table(cheese,depip,resp);
GT = groupsummary(T,{'cheese','depip'},{12,5},'median','resp');
The above code should group cheese into 12 groups, within those group depip into 5 groups and then compute the median for the data stored in resp for each of the 12*5 groups.
For earlier releases can probably achieve a similar result by using some combination of findgroups / splitapply and discretize.
  댓글 수: 5
Valeria Lorenzoni
Valeria Lorenzoni 2018년 5월 9일
How can I replace the values of each range by its mean. For example for GT(:,1) replace [0, 30) with 15 and so on?
Razvan Carbunescu
Razvan Carbunescu 2018년 5월 9일
If you want to do computation afterwards I'd say it's probably easier to convert both to double and use indexing to expand the new names to what you want
newcatscheese = (15:30:345)'; % making into column
GT.disc_cheese = newcatscheese(double(GT.disc_cheese))
If you want to keep them as categorical can probably change the names of the categories with renamecats.
newcatsdepip = {'25','75','125','175','225','275'};
GT.disc_depip = renamecats(GT.disc_depip,categories(GT.disc_depip),newcatsdepip)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Data Preprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by