mean, standard deviance, variance simplify the code if possible?
1 回表示 (過去 30 日間)
古いコメントを表示
I have a user input table, it allows data to be entered as strain as (X) and stress as (Y), is there a function that can simplify my formula that i used for mean standrad deviation and variance
- also i only used strain (X) data for the computation, is it mathematically correct?
%Data Extracted from UITable
d = str2double (app.UITable.Data);
%Each Point in Strain
Px1 = d(1,1);
Px2 = d(2,1);
Px3 = d(3,1);
Px4 = d(4,1);
Px5 = d(5,1);
Px = Px1+Px2+Px3+Px4+Px5;
%Each Point in Stress
Py1 = d(1,2);
Py2 = d(2,2);
Py3 = d(3,2);
Py4 = d(4,2);
Py5 = d(5,2);
Py = Py1+Py2+Py3+Py4+Py5;
%Young Modulus Formula
R = Py / Px ;
%Mean Formula
M = Px / 5 ;
%Standard Deviation Formula
N = (Px1-M)^2+(Px2-M)^2+(Px3-M)^2+(Px4-M)^2+(Px5-M)^2;
S = sqrt( N / 5 );
%Variance Formula
V = S^2;
app.YoungsModulusEditField.Value = R;
app.MeanEditField.Value = M;
app.StdDevEditField.Value = S;
app.VarianceEditField.Value = V;
0 件のコメント
回答 (1 件)
Pravin Jagtap
2020 年 5 月 4 日
You can read the values from the matrix and calculate the mean in one line to clean up some code. For examples, replace
%Each Point in Strain
Px1 = d(1,1);
Px2 = d(2,1);
Px3 = d(3,1);
Px4 = d(4,1);
Px5 = d(5,1);
Px = Px1+Px2+Px3+Px4+Px5;
with
Px = mean(d(:,1));
On similar lines you can clean up other part of code.
I would recommend you to follow the documentation links mentioned below:
For 'mean':
For 'Standard deviation':
For 'Variance'
Hope this will help
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Stress and Strain についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!