mean, standard deviance, variance simplify the code if possible?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (1)
Pravin Jagtap
el 4 de Mayo de 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
0 comentarios
Ver también
Categorías
Más información sobre Stress and Strain en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!