There is no direct way to tell dummyvar to use a previously created dummyvar predictor matrix as a reference. So, in this case you would need to dummy-code each categorical variable separately and then do the same for the test vector. The following example should explain the workflow you would need to follow:
Say you have two categorical variables: Month, with categories, 1 to 12 and LeapYear with categories 0 and 1.
In this case, you would need to use the following code:
Monthcat = categorical(Month);
LeapYearcat = categorical(LeapYear);
dumMonth = dummyvar(Monthcat);
dumLeap = dummyvar(LeapYearcat);
dumPredictorMat = [dumMonth dumLeap];
MonthTest = 4;
LeapYearTest = 1;
MonthTestcat = categorical(MonthTest,1:12);
LeapTestcat = categorical(LeapYearTest,0:1);
dumMonthTest = dummyvar(MonthTestcat);
dumLeapTest = dummyvar(LeapTestcat);
dummyTestMat = [dumMonthTest dumLeapTest];
Now you should be able to use the dummyTestMat as an input to the predict function of the model to generate the corresponding predicted responses.
Best Answer