이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
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.
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 ?
![](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 (한국어)