Why does assigning a categorical with empty and non empty values result in a error in MATLAB 8.2(R2013b)?

6 views (last 30 days)
I tried to execute the following commands in MATLAB R2013b
 
>> D_num = 10*(1:10)';
>> C_num = [1:3, NaN, NaN, 1]';
>> D = nominal(D_num);
>> C = nominal(C_num);
>> D(10+(1:4), :) = C(1:4, :)
and I receive the following error:
Subscript indices must either be real positive integers or logicals.
Error in categorical/subsasgn>convertCodesLocal (line 100)
newlyAssigned(unique(bcodes)) = true;
Error in categorical/subsasgn (line 51)
[bcodes,anamesNew] = convertCodesLocal(bcodes,bnames,anames,a.isProtected);
I could execute the above code with no issue in MATLAB R2013a. How do I resolve this?

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 16 Jan 2014
There is an unexpected behavior in MATLAB 8.2 R2013b in the way that assignment into categorical arrays is handled. This error is due to assigning category arrays with 'NaN' and nonempty values into another category array.
The workaround to this issue is to pre-define 'NaN' as a category. For example:
>> D_num = 10*(1:10)';
>> C_num = [1:3, NaN, NaN, 1]';
>> D = nominal(D_num,num2str(D_num),unique(D_num));
>> C = nominal(C_num,{'1','2','3','NaN'},[1 2 3 NaN]);
>> D(10+(1:4), :) = C(1:4, :)
This will return the expected result as shown:
D =
10
20
30
40
50
60
70
80
90
100
1
2
3
NaN

More Answers (0)

Products


Release

R2013b

Community Treasure Hunt

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

Start Hunting!