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.

 Accepted Answer

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 Comments

Thank you very much for your help, it is practically to what I was trying to get. The only problem is that I want specifically to take groups of depip that go from 0-50, 50-100, 100-150,150-200. And the problem here is that it divides automatically depip into 5 groups independently to the creteria given (every 50m). Another question, is it possible to plot these values with a 3d polar plotting?
You can also specify the bins directly if you know they need to be in a certain range.
groupsummary(T,{'cheese','depip'},{0:30:360,0:50:300},'median','resp');
Regarding the plotting aspect I am less familiar but there is a file exchange submission for 3D polar plotting
There are also some previous MATLAB Answers on the topic.
Can probably also use scatter3 after building the x, y coordinates from the groups information.
Thank you it worked perfectly!
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?
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)

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!