MATLAB: Index exceeds matrix dimensions.

matrix

f = figure('Position',[10 10 600 600]);
dat = {-1,1,1;0,-1,0;0,0,-1;1,0,0};
cnames = {'1','2','5'};
rnames = {'1','2','3','4'};
t = uitable('Parent',f,'Data',dat,'ColumnName',cnames,...
'RowName',rnames,'Position',[10 10 590 590]);
blnA = logical( A == -1 );
blnOut = find(any(A == -1,2));
rnames{max(blnOut)};
negcolumn = find(A(min(blnOut),:) == 1);
cnames{max(negcolumn)};
dU(5)=7;
dU(cnames{max(negcolumn)})
Error message occurred. I couldn't find the mistake.(cnames{max(negcolumn)})=5 So it must be dU(5)=7 but error message
Index exceeds matrix dimensions.

Best Answer

Perhaps
A = cell2mat(dat);
but I can't figure out what dU is for - it's not being used. Anyway, look at this code:
dU(5)=7;
maxValue = max(negcolumn)
index = cnames{maxValue} % Gives string '5'
dU(5) % Works fine.
dU(cnames{max(negcolumn)}) % dU('5') = du(53) which is not defined because dU has only 5 elements.
You can't have the string '5' be the index into an array. Perhaps you wanted cnames to be a cell array that stored integers, not strings:
cnames = {1,2,5};
which works, though I still don't know what you're after.