Im given a matrix similar to this but longer. I ignore the nan values when calculating the average. The problem I have is that my output is only the last rows average and I want each row to provide me with a separate average.
Let me know if I should clarify more!
shortmeasurements = [ 300 301 303;
301 302 nan;
304 307 306;
nan 303 306;
nan 301 nan;]
I think I'm getting an error from my "mean" line. "Tube" represents the n-by-3 matrix I'm taking the average of.
failcount = 0; %//initialize variables
flag = false;
for n = (1:size(Tube,1)) %//number of elements in first row
if all(isnan((Tube(1,:))))== 1 %// if all values in row 1 are NaN
failcount = failcount + 1; %//fail count + 1
if failcount == 1 %//first time through loop
airSpeed = isnan; %//airspeed nan
else
airSpeed(n,1) = (airSpeed( n-1,1)) %//previous air speed
end
else
airSpeed = mean(Tube(n,~isnan(Tube(n,:)))); %//taking the mean
Aucun commentaire:
Enregistrer un commentaire