Taking mean of only specific values in column vector.
1 次查看(过去 30 天)
显示 更早的评论
Hi , i have a column vector with 60 rows and 1 column as shown below. I want to take mean of only the values i.e 0.13 Can anybody suggest me how can i do that in MATLAB
[0.13
0.26
0.39
0.52
0.65
0.13
0.26
0.39
0.52
0.13
0.26
0.39
0.13
0.26
0.13
0.13
0.26
0.39
0.52
0.65
0.13
0.26
0.39
0.52
0.13
0.26
0.39
0.13
0.26
0.13
0.13
0.26
0.39
0.52
0.65
0.13
0.26
0.39
0.52
0.13
0.26
0.39
0.13
0.26
0.13
0.13
0.26
0.39
0.52
0.65
0.13
0.26
0.39
0.52
0.13
0.26
0.39
0.13
0.26
0.13]
Thank you
19 个评论
Ahmad Bilal
2018-10-11
Sorry . Let me again ask the question in an another way. I have an excel with 2 column vectors x and y. Now x has different values such as 0.13,0.26,0.39 and so on. Now, I want to take mean in such a way that for every x=0.13 in column x there is corresponding value of y.
I want to take mean of values of y vector that correspondsto only x=0.13. PLease see an attached excel file.I hope this clears my point now.
Ahmad Bilal
2018-10-11
This is my code as follows :
dataset = xlsread('Test Excel file Mean and std.xlsx');
x = dataset(:,1);
y = dataset(:,2);
scatter(x,y,'*');
a = mean(y(x==0.13));
hold on
plot(a,y,'r+');
grid on
Image Analyst
2018-10-11
Torsten, please put your answer down below in the official Answer section, rather than as a comment up here where people ask for clarification. that way you can get credit (reputation points) for it. ?
Image Analyst
2018-10-11
Ahmad, I know. And I gave you a complete turnkey solution below. Did you try/see it?
Ahmad Bilal
2018-10-11
I have tried it. It works perfectly fine . Now I want to display this point in my plot as i mentioned below. can you help me in this regard
采纳的回答
Image Analyst
2018-10-11
Try this:
fileName = 'Test Excel file Mean and std.xlsx';
data = xlsread(fileName)
rows = ismembertol(data(:, 1), 0.13, 0.001) % Rows where column 1 = 0.13
column2 = data(:, 2);
theMean = mean(column2(rows))
10 个评论
Ahmad Bilal
2018-10-11
No my code looks like as follows :
dataset = xlsread('Test Excel file Mean and std.xlsx');
x = dataset(:, 1);
y = dataset(:, 2);
scatter(x,y,'*');
grid on
a = ismembertol(dataset(:, 1), 0.13, 0.001); % Rows where column 1
= 0.13
theMean = mean(y(a));
Now actually i want to display this mean valuei.e the mean in my scatter plot which corresponds to x=0.13. How can I do that ?
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/193105/image.jpeg)
Ahmad Bilal
2018-10-11
Like for every 0.13 in axis there is a stream of points in y axis. So i want to plot mean of y streams at x =0.13
Ahmad Bilal
2018-10-11
Can anybody help me in that how can i display mean values at x= 0.13 in the above plot.
Image Analyst
2018-10-11
Try this:
hold on;
plot(0.13, theMean, 'r*', 'LineWidth', 2, 'MarkerSize', 15);
Ahmad Bilal
2018-10-13
Now I want to calculate standard deviation for values corresponding to x=0.13 Actually i want to plot error bar which shows the error of points with respect to mean value that I have already calculated. I know how to plot error bars but i am confused how to use standard deviation as errorbars. Can anybody help me in this regard ???
Ahmad Bilal
2018-10-13
I get this point but i am still confused how to use this std deviation as error bars. I know the syntax of error bars.
Actually My current figure looks as follows:I have already calculated mean shown as red squares.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/193149/image.jpeg)
Now I want to use standard deviation as error bars that will show my error of each blue points with respect to mean i.e red squares.
Can u suggest how can i display this kind of picture ? Thanks
Ahmad Bilal
2018-10-13
can you help me here with code snippet based on above mentioned variable in code uptil now I have the folllowing code as follows :
dataset = xlsread('Test Excel file Mean and std.xlsx');
x = dataset(:, 1);
y = dataset(:, 2);
scatter(x,y,'*b');
grid on
a = ismembertol(dataset(:, 1), 0.13, 0.001); % Rows where column
1 = 0.13
b = ismembertol(dataset(:, 1), 0.26, 0.001); % Rows where column
1 = 0.26
c = ismembertol(dataset(:, 1), 0.39, 0.001); % Rows where column
1 = 0.39
d = ismembertol(dataset(:, 1), 0.52, 0.001); % Rows where column
1 = 0.52
e = ismembertol(dataset(:, 1), 0.65, 0.001); % Rows where column
1 = 0.65
values = [x y];
theMean1 = mean(y(a));
theMean2 = mean(y(b));
theMean3 = mean(y(c));
theMean4 = mean(y(d));
theMean5 = mean(y(e));
hold all;
plot(0.13, theMean1, 'rs','MarkerFaceColor','r','MarkerSize',10);
plot(0.26, theMean2, 'rs','MarkerFaceColor','r','MarkerSize',10);
plot(0.39, theMean3, 'rs','MarkerFaceColor','r','MarkerSize',10);
plot(0.52, theMean4, 'rs','MarkerFaceColor','r','MarkerSize',10);
plot(0.65, theMean5, 'rs','MarkerFaceColor','r','MarkerSize',10);
% Here I want to use error bar command or box plot command to display error from mean values to each blue points for each corresponding x =0.13 0.26 and so on
xlabel('distance d b/w mic pairs[cm]');
ylabel('\phi_r_a_t_i_o');
title('Relationship between \phi ratio and distance between Mic
Pairs for Array 3');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Line Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)