I want to calculate the RMS, MEAN, STD of the first three elements of any predefine array and store it in new array and then calculate the same for the next three elements
6 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to calculate the RMS, MEAN, STD of the first three elements of any predefine array and store it in new array and then calculate the same for the next three elements and store it in the same new array and so on till last.
0 Kommentare
Antworten (1)
dpb
am 9 Jun. 2022
Bearbeitet: dpb
am 9 Jun. 2022
N=size(x,1); % number rows in x
g=kron([1:N/3].',ones(3,1)); % grouping variable by three
[gmean,gstd,grms]=grpstats(x,g,{'mean','std',@rms})); % compute
NB: the above requires N be an even multiple of 3
2 Kommentare
dpb
am 10 Jun. 2022
Bearbeitet: dpb
am 10 Jun. 2022
Use "the MATLAB way" I showed you instead.
"x" is your "predefined array"; simply use your variable name. You'll want to add error checking or otherwise handle the case of other than a multiple of three records if it is ever possible that condition can arise; we don't have sufficient information to know about edge case.
You can use/rearrange the returned statistics arrays with whatever variable structure/names you wish for the end result, but compute the results efficiently with grouping a variable.
mean=std(B);
Don't use mean as a variable; it's the builtin function for the statistic; doing this will create all sorts of unexpected havoc.
Siehe auch
Kategorien
Mehr zu Workspace Variables and MAT-Files finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!