Changing Array Elements with logical indexing

조회 수: 16 (최근 30일)
MiauMiau
MiauMiau 2014년 4월 4일
댓글: per isakson 2014년 4월 4일
Hi
If I want to change all NaNs in an array A to zero, the following works:
A(isnan(A))=1000
As far as I see the isnan(A) returns nothing but an array of 1's and 0's.
But if I do the following:
B = [ 1 5 8]; B([0 0 1]) = 1000;
to replace the 8 with a 1000, I get an error - why?

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 4월 4일
B = [ 1 5 8];
B(logical([0 0 1])) = 1000;
  댓글 수: 2
MiauMiau
MiauMiau 2014년 4월 4일
thx...then the result of the isnan are logical 1s and 0s?
per isakson
per isakson 2014년 4월 4일
Yes,
>> class( isnan( nan ) )
ans =
logical
>>

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

추가 답변 (1개)

TAB
TAB 2014년 4월 4일
B(B==8)=1000;

카테고리

Help CenterFile Exchange에서 Operators and Elementary Operations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by