how to calculate the average?
    126 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Lilya
      
 am 19 Okt. 2021
  
    
    
    
    
    Kommentiert: Lilya
      
 am 19 Okt. 2021
            Hi, 
I have a matrix that has a dimension of 200*59. I want to calculate the average of the first 6 rows for each column to get 1*59
I've written this loop
for i=1:59
Tavg(i)=nanmean(squeeze(temp(1:6,i))); 
end
I am not sure if the loop is correct or not!
any help is appreciated 
0 Kommentare
Akzeptierte Antwort
  Kevin Holly
    
 am 19 Okt. 2021
        
      Bearbeitet: Kevin Holly
    
 am 19 Okt. 2021
  
      Lilya,
temp = rand(200,59);%random matrix for demonstration purposes
Tavg = mean(temp(1:6,:)) %The first input is a vector of the rows 1 through 6 and the second input is a colon (:), which includes all elements (in this case all columns).
if you have NaN values that you want to ignore:
Tavg = mean(temp(1:6,:),'omitnan')
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!

