I have 2-D data from a measurement that looks as below:
The noise causes the Y data to be in the range from [4.03, 4.1]. How can I obtain a mean value (x, y) for each group of points, eg for the graphic this would be around (0.3, 4.07), (1.6, 4.08), (2.3, 4.05), (3, 4.07)?
I saw something about nlfilter, but most example about that represent a 2-D image. Thanks for your help!
EDIT:
I generate the plot below with:
plot(t, y);
The t data looks as:
t(some_condition(1:40))
ans =
1.0e-04 *
Columns 1 through 6
0.0216 0.0216 0.0216 0.0216 0.0216 0.0217
Columns 7 through 12
0.0217 0.0217 0.0217 0.0217 0.0218 0.0928
Columns 13 through 18
0.0928 0.0928 0.0928
>> mean(t(some_condition))
ans =
1.6686e-05
So, I only get one value for the mean in t, while I want to have 4 means (actually, the 2 dots around 0.8) are noise too.
You can try the following:
x_filter = [0.03 0.16 0.23 0.30]*1e-5; % Insert value you want to filter here and exluce those which not
for i = 1:numel(x_filter)
ind = abs(t-x_filter(i))<0.01e-5; % Or any other offset
x_m = mean(t(ind));
y_m = mean(y(ind));
plot(x_m,y_m,'x','MarkerSize',20);
end
In MATLAB the mean function operates column-wise, so using mean(ydata) would give you an array containing the mean for each x-position. If I got you right, here is a sample code which does what you are after (I think):
clear
clc
%// Generate dummy data
x = repmat(1:4,10,1);
y = rand(10,4);
My = mean(y)
My looks like this:
My =
0.5854 0.6799 0.5431 0.2933
Then plot the points using scatter:
hold on
for k = 1:size(y,2)
scatter(x(:,k),y(:,k))
markerarea = 200;
scatter(k,My(k),markerarea,'filled','d') %// Represent the mean as a diamond.
end
hold off
axis([0 5 0 1])
which looks like this:
Is this what you had in mind? If not please tell me I'll edit/remove my answer :)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.