Save mean values in additional column
1 view (last 30 days)
Sputum_Idx(:,1) = unique(Arg_Range1peaks(:,3));
for i = 1:numel(Sputum_Idx(:,1))
MeanV1(i,1) = mean(Arg_Range1peaks(ind));
Mean1 = [MeanV1 Sputum_Idx(:,1)];
Hello. After obtaining the N x 3 vector as shown in the picture above ([Range1 peaks]), I listed it in order of size in columns 3 through indexing ([Arg_Range1 peaks]).
In addition, the average values of column 1 values([Arg_Range1 peaks]) were saved for rows with the same values in column 3 ([Mean1]).
As shown in the rightmost figure, we would like to place mean values of [Mean1] corresponding to column 3 in column 4 of [Arg_Range1 peaks]. What should I do?
DGM on 27 Nov 2021
Something like this
% dummy data
N = 15;
Range1peaks = [10*rand(N,1)-70 2*rand(N,1)+4 randi([0 5],N,1)]
[~,Peaks_index1] = sort(Range1peaks(:,3),1,'ascend');
Arg_Range1peaks = Range1peaks(Peaks_index1,:);
% append column, take mean, fill
Arg_Range1peaks = [Arg_Range1peaks zeros(size(Arg_Range1peaks,1),1)];
Sputum_Idx = unique(Arg_Range1peaks(:,3));
for i = 1:numel(Sputum_Idx)
Arg_Range1peaks(ind,4) = mean(Arg_Range1peaks(ind,1));
% show result