mean, standard deviance, variance simplify the code if possible?
조회 수: 2 (최근 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!