MATLAB: END or colon can only be used to index arrays

colonmatlab gui

I built a GUI, and made a function named training. I load my databasetraining which has two variables in it, C sized 144×300 and D sized 1×300. Then I split my data to TrainData and TrainLabels like this
TrainData = C(:,1:2:end);
TrainLabels = D(1:2:end);
But, I found a warning in TrainLabels = D(1:2: end);, and got a message that "END or colon can only be used to index arrays. This might be an incorrect use."
Why so? Would you fix it? Thank you.

Best Answer

At the command line, give the command
which D
whos D
I suspect that you have not defined D in the scope.
You could get the warning if you used load() without any output, expecting that the load() would bring D into the workspace. The parser does not check to see what variables are in a .mat file. "poofing" variables into existence is not recommended.