Need to figure out how to find the average.

조회 수: 1 (최근 30일)
Olivia Gilliam
Olivia Gilliam 2021년 2월 23일
댓글: Walter Roberson 2021년 2월 23일
This is what I have so far:
load ('sensorData.mat', 'measurements')
A = measurements;
k=0;
for elevationEstimates = nanmean (A,2)
if isnan(elevationEstimates(1:150))
k=k+1;
end
end
elevationEstimates
The problem is, I don't know how to get the sensor to read NaN as zero so that it doesn't affect the average of a certain row.
This is only an excerpt of the data. For example, if I wanted to find the average of row 8, how do I only calculate the 2 numbers for the average? The instructions explain it better than I do.
  댓글 수: 1
per isakson
per isakson 2021년 2월 23일
"The problem is, I don't know how to get the sensor to read NaN as zero so that it doesn't affect the average of a certain row. " Zero would affect the average! Better:
>> nanmean([nan,3,1])
ans =
2

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2021년 2월 23일
You are intended to loop over the rows for this task, not process the entire data first.
Extract a row. Take nanmean of the row. Is the mean nan? If so increment a counter; if the counter is high enough, quit; if it is not high enough, use the previous mean. If the mean was not nan use this mean and update the notion of previous mean and reset the counter of consecuative nan.
  댓글 수: 2
Olivia Gilliam
Olivia Gilliam 2021년 2월 23일
How do I loop over the rows? Instead of the entire data set?
Walter Roberson
Walter Roberson 2021년 2월 23일
nrows = size(A,1);
for row = 1 : nrows
A(row,:)
end

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by