You are now following this question
- You will see updates in your followed content feed.
- You may receive emails, depending on your communication preferences.
Taking mean of only specific values in column vector.
1 view (last 30 days)
Show older comments
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 Comments
Ahmad Bilal
on 11 Oct 2018
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.
madhan ravi
on 11 Oct 2018
Edited: madhan ravi
on 11 Oct 2018
Contain the values as such values = [x y]
Ahmad Bilal
on 11 Oct 2018
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
on 11 Oct 2018
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. ?
madhan ravi
on 11 Oct 2018
Edited: madhan ravi
on 11 Oct 2018
Add this line values = [x y] Before mean command
Image Analyst
on 11 Oct 2018
Ahmad, I know. And I gave you a complete turnkey solution below. Did you try/see it?
Ahmad Bilal
on 11 Oct 2018
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
Accepted Answer
Image Analyst
on 11 Oct 2018
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 Comments
Ahmad Bilal
on 11 Oct 2018
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 ?
Ahmad Bilal
on 11 Oct 2018
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
on 11 Oct 2018
Can anybody help me in that how can i display mean values at x= 0.13 in the above plot.
Image Analyst
on 11 Oct 2018
Try this:
hold on;
plot(0.13, theMean, 'r*', 'LineWidth', 2, 'MarkerSize', 15);
Ahmad Bilal
on 13 Oct 2018
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
on 13 Oct 2018
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.
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
on 13 Oct 2018
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');
More Answers (0)
See Also
Categories
Find more on Bar Plots in Help Center and File Exchange
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!An Error Occurred
Unable to complete the action because of changes made to the page. Reload the page to see its updated state.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)