Calculate variablity over specified interval and apply corresponding calculation back to formula

1 vue (au cours des 30 derniers jours)
I'm trying to reproduce a calculation I've seen in a paper called variablity. It's defined as follows:
so Xvariability = sqrt((Xn-Xavg)^2) for 1 to n
Xavg needs to be calculated over a regular interval, in this case, a Y interval of 0.5 with a sensor recording X at irregular intervals of Y.
In the example below, what's the best way to calculate Xavg for 0-0.5, 0.5-1.0, 1.0-1.5 and 1.5-2.0, then apply those Xavg values in the Xvariabilty formula back to each original value of X with corresponding Xavg for the correct interval?
%tables
Y = [0;0.0542;0.0801;0.2222;0.3959;0.4572;0.5110;0.5348;0.5712;0.6099;0.6437;0.6799;0.8011;0.8928;0.9590;1.0110;1.13;1.22;1.31;1.43;1.5;1.61;1.73;1.83;1.91;2.0];
X = [118.7000;207.8000;139.6000;176.0000;177.8000;229.3000;242.4000;138.9000;85.7000;140.8000;164.5000;125.4000;189.8000;164.0000;118.4000;211.4000;148.7000;207.8000;119.6000;116.0000;117.8000;129.3000;242.4000;198.9000;285.7000;130.8000];
YX = [Y,X];

Réponse acceptée

Bhavana Ravirala
Bhavana Ravirala le 17 Fév 2022
Hi Daniel,
When we apply a logical condition on an array(Y) it will produce logical array, by giving this as an index to another array(X) we will get the corresponding values.
Y = [0;0.0542;0.0801;0.2222;0.3959;0.4572;0.5110;0.5348;0.5712;0.6099;0.6437;0.6799;0.8011;0.8928;0.9590;1.0110;1.13;1.22;1.31;1.43;1.5;1.61;1.73;1.83;1.91;2.0];
X = [118.7000;207.8000;139.6000;176.0000;177.8000;229.3000;242.4000;138.9000;85.7000;140.8000;164.5000;125.4000;189.8000;164.0000;118.4000;211.4000;148.7000;207.8000;119.6000;116.0000;117.8000;129.3000;242.4000;198.9000;285.7000;130.8000];
k= Y<0.5 & Y>=0; % logical array for the values of Y between 0-0.5
l= Y<1 & Y>=0.5; % logical array for the values of Y between 0.5-1
m=Y<1.5 & Y>=1; % logical array for the value of Y between 1-1.5
n=Y<=2 & Y>=1.5; % logical array for the value of Y between 1.5-2
% X(k)-gives the corresponding values of X with respect to Y
% mean(X(K))-gives the average, sum()-gives the sum of elements
% .^2-performs elementwise square operation.
Xvar=sqrt(sum((X(k)-mean(X(k))).^2)+sum((X(l)-mean(X(l))).^2)+sum((X(m)-mean(X(m))).^2)+sum((X(n)-mean(X(n))).^2));
For more information about logical array refer the documentation below:
Hope this helps!

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by