Standard deviation, Mean values for each class
現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
古いコメントを表示
Hello, I have a problem with a code.
First of all I have a .csv file with 2 columns, as I show you in the Image. in the first column the data are split by 0.5 (1,1.5,2).

I would like to find mean values and standard deviation for each of one class, I mean one value of standard deviation and mean value for the data with 1 in , one value of standard deviation for the 1.5 and one value of standard deviation for the 2.
I mean I wanna use the errorbar command.
I think I should use a loop who reads 1st column one by one but I can not make it.
Could anyone help me?
採用された回答
data = [ 1 1 1.5 1.5 2 2; 10 9 7 6 3.5 8]',;
[dataMean, dataStd] = grpstats(data(:,2), data(:,1), {'mean', 'std'})
If your data are in table format,
Tstats = grpstats(T, 'data1', {'mean','std'});
% ^^^^^ VariableName for column 1
If you don't have Stats & Machine Learning Toolbox,
stats = splitapply(@(x)[mean(x), std(x)], data(:,2), findgroups(data(:,1)));
8 件のコメント
Ivan Mich
2020 年 3 月 24 日
Thank you firt of all.
I am trying tu run your suggested commands but in command window returns me the following message:
Attempt to execute SCRIPT std as a function:
I don't know why is this happening.
could you help me?
std is a builtin Matlab function. However, you have a script (m-file) named "std.m" so when you try to use the std() function, Matlab is accessing your std.m script instead.
Solution: rename the std.m file. Avoid naming matlab files after commonly used functions. You may need to rehash your path afterwards using rehash path.
To find your std.m file, execute: which std -all
Ivan Mich
2020 年 3 月 24 日
ok,
One more question. Do you know how to plot thw errorbars in a plot. I mean i would like to make a plot with xvaluew, y values from my .csv data, and in the same plot i would like to show the errorbars..
Check out these errorbar examples. If you have trouble applying them to your data, let me know what the trouble is. https://www.mathworks.com/help/matlab/ref/errorbar.html#bvc1i63-8
Ivan Mich
2020 年 3 月 24 日
the problem is that I would like to plot my final plot like this

but I can't make it. This plot is from an another software.
in x axis there are the values in column 1, y values are in column 2 .
from the command
stats = splitapply(@(x)[mean(x), std(x)], data(:,2), findgroups(data(:,1)));
you suggested are coming out 2 columns each of them has 3 values.
Do you know how to make it?
Adam Danz
2020 年 3 月 24 日
Regarding the errorbar question, it's really easy.
- Use the errorbar function to plot the main line and errorbars
- Add the values from the main line to the error values to produce the dotted lines.
% lower error line
plot(x, y-err)
% upper error line
plot(x, y+err)
Regarding the splitapply output, the rows are the groups (1, 1.5, 2) and the columns are [mean, std].
well, I send you the full code in order to see it and tell me where I am wrong:
clc
clear
filename1= 'e.xlsx'
[d1,tex]= xlsread(filename1);
x=d1(:,1);
y=d1(:,2);
stats = splitapply(@(y)[mean(y), std(y)], y, findgroups(x));
meanvalues=stats(:,1)
stdvalues=stats(:,2)
err=errorbar(meanvalues,stdvalues)
% lower error line
hold on
plot(x,y,'bo')
hold on
plot(x, y-err)
hold on
% upper error line
plot(x, y+err)
Command window send me the message :
Undefined operator '-' for input arguments of type 'matlab.graphics.chart.primitive.ErrorBar'.
Error in eo (line 24)
Adam Danz
2020 年 3 月 25 日
plot(x, y-err)
plot(x, y+err)
1) You should be using the meanvalues insetad of x.
2) err, in your code, is the handle to the error bars. You should be using the stdvals.
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Errorbars についてさらに検索
参考
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)
