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

3 Ansichten (letzte 30 Tage)
sydney salvador
sydney salvador am 1 Mai 2020
Beantwortet: Pravin Jagtap am 4 Mai 2020
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;

Antworten (1)

Pravin Jagtap
Pravin Jagtap am 4 Mai 2020
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

Kategorien

Mehr zu Stress and Strain finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by