Removing invalid results

조회 수: 6 (최근 30일)
Michael
Michael 2011년 7월 12일
Hi, I'm having a problem removing part of my output that is invalid. Basically I have a matrix, and certain values within that matrix are implausible, and I want to replace those values with a value that won't affect calculations. So for example my matric might be [1 2 3 4 30], but 30 might be implausible, so I want to replace it with another value that doesn't affect calculations so that, for example, if i were to average the values I would get (1+2+3+4)/4 not divided by 5. Any ideas would be appreciated. Thank you

채택된 답변

Sean de Wolski
Sean de Wolski 2011년 7월 12일
Replace all of your implausible values (whatever criteria you use to determine that) with nan. Then apply your function to the non nan part of your data. There are some built-in nan ops already others would be easy to write.
A = [1 2 3 4 30]
A(A>10) = nan;
idx_care = ~isnan(A);
the_mean = sum(A(idx_care))/sum(idx_care);

추가 답변 (1개)

the cyclist
the cyclist 2011년 7월 12일
x = [1 2 3 4 30];
x(x>10) = NaN;
meanx = nanmean(x); % Will ignore NaN
  댓글 수: 2
Sean de Wolski
Sean de Wolski 2011년 7월 12일
stats toolbox required!
the cyclist
the cyclist 2011년 7월 13일
D'oh!

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

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by