Index exceeds matrix dimensions.
古いコメントを表示
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.
1 件のコメント
the cyclist
2013 年 6 月 8 日
I cannot run your code, because I do not have the array A. Is it possible for you to post self-contained code that will execute and show that error?
採用された回答
その他の回答 (1 件)
Walter Roberson
2013 年 6 月 8 日
0 投票
You have not defined dU()
cnames indexed by a number gives you a string. Indexing an array by a string is not impossible but seldom gives the expected answer: in your case it would be equivalent to asking for dU([49 50])
You need to remember that '1','2','5' are strings and that you almost never index arrays at strings; arrays get indexed at row numbers and column numbers.
If you need to be able to access an array by the name of a row, or the name of a column, then you need to use the MATLAB database object, which is part of the Statistics toolbox.
5 件のコメント
Light
2013 年 6 月 8 日
Image Analyst
2013 年 6 月 8 日
I thought I answered it. You accepted my answer.
Light
2013 年 6 月 8 日
Walter Roberson
2013 年 6 月 8 日
Here, index is the string '35', not the numeric value 35.
Image Analyst
2013 年 6 月 8 日
See my answer to your new explanation in your duplicate question: http://www.mathworks.com/matlabcentral/answers/78455#answer_88183
カテゴリ
ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!