How to create a mean bar for individual groups?

2 ビュー (過去 30 日間)
matlab_newbie
matlab_newbie 2011 年 5 月 23 日
I have a scatter plot x-axis is has two points - smoker and non-smoker y-axis is my variable of choice.
I am wondering how to create a mean bar for smoker and non smoker groups (something similar to setting Tools->Data Statistics where I would pick Y-mean) In this case however I dont need a unified mean across two points, I need individual mean for each point.
You help is greatly appreciated!

回答 (1 件)

Matt Tearle
Matt Tearle 2011 年 5 月 23 日
Can you clarify what you mean by "x-axis is has two points - smoker and non-smoker". For a scatter plot you need equal-sized x and y vectors. Do you have a separate vector that identifies smoker/nonsmoker? If so, why not split into two groups and plot together on the same axes:
% identify smokers
idx = strcmp('Y',smoker);
% make plot
plot(x(idx),y(idx),'o',x(~idx),y(~idx),'o')
meansmoke = mean(y(idx));
meannonsm = mean(y(~idx));
line(xlim,meansmoke*[1,1],'color',[0 0 1])
line(xlim,meannonsm*[1,1],'color',[0 0.5 0])
(Here I'm assuming you have a char array smoker that is either 'Y' or 'N')

カテゴリ

Help Center および File ExchangeScatter Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by