Iterations on field conditions of a structure array
Afficher commentaires plus anciens
Hi. I am working with a structure array S (1 X 50,000) with 10 fields. I want to find few paramters based on few conditions. Is there a simple way to do such iterations shown below using a loop and save them in a structure?
f1 = [S.f1];
f2 = [S.f2];
f3 = [S.f3];
%% ITERATION 1:
idx1 = f1 > 0 & f1 <=10;
% Parameter 1
num1 = numel(f1(idx1));
avg1 = mean(f2(idx));
sd1 = std(f2(idx));
% Parameter 2
idx2 = f3 > 0;
idx = idx1 & idx2;
pos_num1 = numel(f1(idx));
pos_avg1 = mean(f2(idx));
pos_sd1 = std(f2(idx));
% Parameter 3
idx2 = f3 < 0;
idx = idx1 & idx2;
neg_num1 = numel(f1(idx));
neg_avg1 = mean(f2(idx));
neg_sd1 = std(f2(idx));
%% ITERATION 2:
idx1 = f1 > 10 & f1 <=20;
% Parameter 1
num2 = numel(f1(idx1));
avg2 = mean(f2(idx));
sd2 = std(f2(idx));
% Parameter 2
idx2 = f3 > 0;
idx = idx1 & idx2;
pos_num2 = numel(f1(idx));
pos_avg2 = mean(f2(idx));
pos_sd2 = std(f2(idx));
% Parameter 3
idx2 = f3 < 0;
idx = idx1 & idx2;
neg_num2 = numel(f1(idx));
neg_avg2 = mean(f2(idx));
neg_sd2 = std(f2(idx));
% so on till 20 interations.
The result should be saved like:
Result.num=[num1,num2,num3.........,num20];
Result.pos_num=[pos_num1,pos_num2,pos_num3,.....,pos_num20];
Result.neg_num=[neg_num1,neg_num2,neg_num2,......,neg_num20];
Result.avg=[avg1,avg2,avg3,.....avg20];
.. so on.
Any help will be highly appreciated.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Structures dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!