No. of elements, mean and standard deviation of a field - conditions on other fields
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi. I am working with a structure array S (1 X 50,000) with 10 fields.
For example,
Here is the input,
S(1).f1=[10,70,30 40,50,60], S(1).f2=[100,20,50,60,70,140] and S(1).f3=[-10,20,-50,42,-70,140] ;
S(2).f1=[16,98,74,47,99], S(2).f2=[101,54,69,20,11] and S(2).f3=[17,-54,69,-20,37];
S(3).f1=...... , S(3).f2=..... and S(3).f3=...........;
S(4).f1=.... , S(4).f2=..... and S(4).f3=............;
.
.
S(i).f1=...., S(i).f2=.... and S(i).f3=............;
Let's say, I have a main condition: 50 < f1 <=100. Based, on this condition I want to calculate few values
I want to know the number of elements in field f1 which satisfy the condition 50 < f1 <=100.
I want to know the number of elements in field f1 whose corresponding f3 > 0.
I want to know the number of elements in field f1 whose corresponding f3 < 0.
I want the mean and sd of f2 elements whose corrseponding f3 > 0.
I want the mean and sd of f2 elements whose corresponding f3 < 0.
Is there a simple way to find the above mentioned parameters?
0 Kommentare
Akzeptierte Antwort
meghannmarie
am 4 Okt. 2019
Bearbeitet: meghannmarie
am 4 Okt. 2019
Maybe something like this?
f1 = [S.f1];
f2 = [S.f2];
f3 = [S.f3];
f1_cond1 = numel(f1(f1 > 50 & f1(f1 <=100)));
f2_idx = f3 > 0;
avg = mean(f2(f2_idx));
sd = std(f2(f2_idx));
5 Kommentare
meghannmarie
am 4 Okt. 2019
Is this what you mean?
idx1 = f1 > 50 & f1 <=100;
idx2 = f3 > 0;
idx = idx1 & idx2;
num1 = numel(f1(idx));
avg1 = mean(f2(idx));
sd1 = std(f2(idx));
idx2 = f3 < 0;
idx = idx1 & idx2;
num2 = numel(f1(idx));
avg2 = mean(f2(idx));
sd2 = std(f2(idx));
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu String Parsing 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!