필터 지우기
필터 지우기

Replace missing elements in an array with NaN

조회 수: 2 (최근 30일)
Anantha Padmanabhan
Anantha Padmanabhan 2016년 10월 4일
편집: Thorsten 2016년 10월 4일
Hello! for i=1:n
scanindex = round((i-1)*pointsperscan+1):round(i*pointsperscan);
filterindex == (i-1)*pointsperscan+find(vlos(scanindex)<=blade_flicker_threshold&...
quality(scanindex)>=quality_range(1)&...
quality(scanindex)<=quality_range(2)&...
power(scanindex)>=power_range(1)&...
power(scanindex)<=power_range(2))';
So i have this code. Scan index reads the entire second values with 312 entries and the filterindex filters based on the scan parameters which results in an array less than 312 entries. I want to keep the size of the filterindex same as the scanindex as I need to rewrite the code for more general purposes and so I was thinking if there was a way to replace the indeces which do not match the filter parameters with NaN values. So the output should read that the size of scanindex and the filterindex are the same!
Thanks

채택된 답변

Thorsten
Thorsten 2016년 10월 4일
You can add the needed number of NaNs to the filterindex;
filterindex(end+1:numel(scanindex) = NaN;
  댓글 수: 2
Anantha Padmanabhan
Anantha Padmanabhan 2016년 10월 4일
Hey, What you say will just add NaNs to the end of the filterindex. I want to have NaNs in the particular index in the filterindex when compared to the scan index. So if scanindex(25) does not satisfy the conditions specified, filterindex(25) must be a NaN.
Thorsten
Thorsten 2016년 10월 4일
편집: Thorsten 2016년 10월 4일
I see. I think that you can use logical indexing to solve your problem:
filterindex = nan(size(scanindex));
fi = (i-1)*pointsperscan+find(vlos(scanindex)<=blade_flicker_threshold&...
quality(scanindex)>=quality_range(1)&...
quality(scanindex)<=quality_range(2)&...
power(scanindex)>=power_range(1)&...
power(scanindex)<=power_range(2))';
filterindex(fi) = true;

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

추가 답변 (0개)

카테고리

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