現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Taking mean of only specific values in column vector.
2 ビュー (過去 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.
madhan ravi
2018 年 10 月 11 日
編集済み: madhan ravi
2018 年 10 月 11 日
Contain the values as such values = [x y]
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. ?
madhan ravi
2018 年 10 月 11 日
編集済み: madhan ravi
2018 年 10 月 11 日
Add this line values = [x y] Before mean command
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 ?

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.

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 で Bar Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)