Clear Filters
Clear Filters

Taking mean of only specific values in column vector.

2 views (last 30 days)
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
Image Analyst
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
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

Sign in to comment.

Accepted Answer

Image Analyst
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
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');

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!