I need help finding the mean/avg of my data set
    3 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    daniel choudhry
 am 19 Nov. 2020
  
    
    
    
    
    Bearbeitet: Cris LaPierre
    
      
 am 19 Nov. 2020
            I need help setting a loop to find the mean/avg of my data set. The data set I am looking at is COPNET_x and COPNET_z each of these data contain 3 trials for each subject(49) and the data length output is 6000.  What i want to do is to aveg the result of these 3 trials for each subject so i can reduce my 6000 data length. Everything in my code works fine. just need help setting up this mean/avg part.
BMI_numbers = [24.97;34.7;19.01;23.59;18.03;27.4;28.92;19.22;21.42;23.45;21.04;19.55;21.34;32.64;27.75;27.38;26.06;31.48;24.34;22.97;21.14;26.05;22.08;25.19;21.74;18.83;21.04;24.06;27.44;22.77;28.22;30.61;26.07;23.03;25.96;28.52;23.11;31.6;25.66;18.73;28.74;21.5;30.3;28.46;19.95;34.29;21.82;28.95;24.34];
BMI_labels = {'Obese';'Non-Obese'};
subject_numbers = [1:49];
trial_numbers = [1:3];
trial_labels = {'OR1','OR2','OR3'};
counter = 0;
fs = 49;
%% Set up loop structure
for sub = subject_numbers
    for trial = trial_numbers
        counter = counter + 1;
        %% Construct file name and full path
        if sub<10
            subject_label = ['0',int2str(sub)];
        else
            subject_label = [int2str(sub)];
        end
        filename_grf = ['PDS',subject_label,'OR',int2str(trial),'grf.txt']; 
        fullpath_grf = [maindirectory,filename_grf];
        %% Load data
        if exist(fullpath_grf,'file')~=0
        data_grf = table2array(readtable(fullpath_grf));
        %% Analyze data
        COPNET_x = data_grf(:,11);
        COPNET_z = data_grf(:,13);
     %%%%%%% How can i find the mean/avg for each subject(3 trials) inside my COPNET data %%%%%%%%%%%%%%%%%%%%%%%%%%%
   for i =1:3
        av(:,i) = mean(COPNET_x);
   end
        %GRFNET_x = data_grf(:,5);
        %GRFNET_y = data_grf(:,7);
 % BMI < 25 = normal , BMI >25 = overwieght 
        n = length(COPNET_x);
        Rx = max(COPNET_x)- min(COPNET_x); %sway range in AP
        Rz = max(COPNET_z)-min(COPNET_z); % sway range in ML
       V_AP = sum(abs(diff(COPNET_x)).*fs)/n; % the average velocity in the AP
       V_ML = sum(abs(diff(COPNET_z)).*fs)/n; % the average velocity in the ML
       Velx_max = max(diff(COPNET_x).*fs); % the max velocity in the AP
       Velz_max = max(diff(COPNET_z).*fs); % the max velocity in the ML
       Vel_total = sum(sqrt(diff(COPNET_x).^2+diff(COPNET_z).^2).*fs)/n; % The total average velocity COP
       Vmax_total = max(sqrt(diff(COPNET_x).^2 +diff(COPNET_z).^2).*fs)/n; % The max velocity COP displacement
        results = [Rx Rz V_AP V_ML Velx_max Velz_max Vel_total Vmax_total];
  %How to categorized my data results  
        %% Output data
        data_output(counter,:) = [sub BMI_numbers(sub) trial results];
        else
            continue
        end
    end
end
0 Kommentare
Akzeptierte Antwort
  Cris LaPierre
    
      
 am 19 Nov. 2020
        
      Bearbeitet: Cris LaPierre
    
      
 am 19 Nov. 2020
  
      Keep your data in a table.
We don't have your data to test with, but here's a simple example.
load patients.mat
data = table(Gender,Age,Weight,Height,Systolic,Diastolic,Location);
% Compute the average of each Gender at each location (similar to each trial for each patient)
avgTbl = groupsummary(data,["Gender","Location"],'mean',["Age","Height","Weight","Systolic","Diastolic"])
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
				Mehr zu Loops and Conditional Statements 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!

