Change
for i=1:length(Library)
checkboxL{i} = uicheckbox(pnl1, 'Text',Library{1,i},...
'Value', 0,...
'Position',[10 390-(i-1)*30 100 100],...
'ValueChangedFcn', @(checkboxL, event) cBoxChanged3(checkboxL));
end
to
nL = length(Library);
for i = 1:nL
checkboxL{i} = uicheckbox(pnl1, 'Text',Library{1,i},...
'Value', 0,...
'Position',[10 390-(i-1)*30 100 100]);
end
cb = @(varargin) cBoxChanged3(checkboxL);
for i = 1:nL
set(checkboxL{i}, 'ValueChangedFcn', cb);
end
Although it might look like those two parts could be merged, they cannot be merged. When you construct the anonymous function referring to checkboxL, a copy of checkboxL as it is right then is taken. If you were still in the middle of filling in the various checkboxL{i} then it would be the partly-filled version that was recorded. So you need to postpone "capturing" the value of checkboxL until after all of the uicheckbox entries have been recorded.