Error ~= Invalid types for comparison

Hi,
I tried to run this code:
D2sub1.RETsm(D2sub1.ID ~= lagmatrix(D2sub1.ID, 1)) = NaN;
and get the error
Error using ~= (line 30)
Invalid types for comparison.
ID is a categorical column.
Is it not possible to compare categorical variables like this?
Thanks,

댓글 수: 4

One can certainly use the ~= operator on categorical variables:
C = categorical([1 2 3]);
D = categorical({'a','b','3'});
C ~= D
ans = 1×3 logical array
1 1 0
Perhaps you could upload your data in a MAT file, so that we can see what is happening in your case?
Luca
Luca 2021년 4월 17일
편집: Luca 2021년 4월 17일
Thank you very much for your fast response. I uploaded a subset and also modified the code according to the new names.
Jan
Jan 2021년 4월 17일
You mention, that ID is a categrical variable, but what is "lagmatrix"? Please post a small example of your inputs.
Luca
Luca 2021년 4월 17일
So it looks like this
ID lagmatrix(ID,1)
10000 NaN
10000 1
10000 1
.
.
.
10000 1
10001 1
10001 2
The lagmatrix command moves the original Matrix down by 1 row. So the switch happens one row later.
There where it is not equal I want that the retrurns are NaN.
I realised that it creates you a variable of type double.
I guess this is the problem.
Thank you very much for your help.

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

답변 (0개)

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

릴리스

R2021a

질문:

2021년 4월 17일

댓글:

2021년 4월 17일

Community Treasure Hunt

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

Start Hunting!

Translated by