필터 지우기
필터 지우기

How do I shift index and keep it as logical?

조회 수: 7 (최근 30일)
Ivy Chen
Ivy Chen 2018년 7월 10일
댓글: Ivy Chen 2018년 7월 10일
I have a index Status as logical and I want to shift it to one row up and one row down as different index array to use for comparison and plotting. I use the following commands:
Last=[NaN;Status(1:end-1)];
Next1=[Status(2:end);NaN];
It creates two new variables, but they become "double", instead of keep them as logical array. Appreciate any help on this.
  댓글 수: 1
OCDER
OCDER 2018년 7월 10일
Can you show the code that generates Status and uses Last and Next1? Just need to see how the logical indices are being used. Also, a logical index cannot store a NaN value. That's why Last and Next1 are being casted to double matrix instead.

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

채택된 답변

James Tursa
James Tursa 2018년 7월 10일
편집: James Tursa 2018년 7월 10일
Logical values can only be 0 or 1. NaN values can only be kept in double or single class variables. You need to come up with a different scheme for whatever you are doing. Will using false instead of NaN work for your downstream code?
  댓글 수: 1
Ivy Chen
Ivy Chen 2018년 7월 10일
thanks, replacing NaN with "false" works nicely!

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

추가 답변 (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