mean, standard deviance, variance simplify the code if possible?

2 ビュー (過去 30 日間)
sydney salvador
sydney salvador 2020 年 5 月 1 日
回答済み: Pravin Jagtap 2020 年 5 月 4 日
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;

回答 (1 件)

Pravin Jagtap
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

カテゴリ

Help Center および File ExchangeStress and Strain についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by