Question

I am trying to take an input such as:

StarT:
2141865 16
2141865 17
2141865 17
2141865 16
2141865 17
2141865 20
2141865 9
2141865 7
2141865 19
2141865 18
2141865 19
2141865 9
2141865 9
2141865 9
2141865 9
2301367 11
2301367 21
2301367 12
2301367 10
2301367 10
2301367 11
2301367 10
2301367 10
2301367 19
2301367 12
2301367 19
2301367 10
2301367 10
2301367 18
2301367 23
2308980 16
2308980 17

into matlab and find the median of the second column with respect to the first column as an index(matching data sets). I also need to then take the mean of that set of data with certain conditions, such as if the original value is within a certain rang (1.5* larger or smaller) then it must adjust the original value to be either 1.5* bigger or smaller (depending on the difference between it and the mode). I have tried the following code and it is giving me close results but not exactly what I need: (I do not have the below code setup for calculating the averages as I cannot figure out how to go about that until the mode is correct)

function Mode_Koi_2

StarData = evalin('base', 'StarP');

global medians;

[medians, ~, Groups] = unique(StarData(:,1),'stable');
medians = [medians, accumarray(Groups, StarData(:,2), [], @median)];


end

Now all I need is a loop or accumarray function to compare the median values in 'medians' with the original values for the corresponding ID in 'StarP', and subsequently adjust them if there is the need to (if the value of the original data is smaller or larger as stated above), then find the average of StarP.

Was it helpful?

Solution

[medians, ~, Groups] = unique(StarT(:,1),'stable');
medians = [medians, accumarray(Groups, StarT(:,2), [], @median)]

results in

medians =

     2141865           9
     2301367          10
     2308980          16
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top