How do I overcome the "Subscript Indices" problem?
1 回表示 (過去 30 日間)
古いコメントを表示
Firstly, I know what it is and why it happens. I just want to know how to overcome the problem.
My code is as followed:
b=zeros(3,3,3); %returns an n-by-n matrix of zeros.
a=[0 1 1; 1 0 1; 1 1 0];
[r, c]=size(a);
for i = 1:r
b(a(i,c-2),a(i,c-1),a(i,c)) = 1;
end
[m, n, o]=size(b);
figure (1)
[x,y,z] = meshgrid(1:m,1:n,1:o);
scatter3(x(:),y(:),z(:),90,b(:),'filled')
3 件のコメント
Walter Roberson
2016 年 6 月 9 日
What is the aim of your statement
b(a(i,c-2),a(i,c-1),a(i,c)) = 1;
taking into account that some of those a values are 0?
採用された回答
John BG
2016 年 6 月 9 日
Thomas
your are trying to index b with a null.
In MATLAB matrix indices have to be >0, and in your for loop you are trying to index b with elements of a, that some happen to be zero.
To index b you need 3 indices, that for instance could be
b(c-2,c-1,c) = 1;
This fixes the
'Subscript indices ..'
crash, yet since don't know the matrix you want to generate, cannot go anyfurther without knowing what do you really want in matrix b.
If you find this answer of any help solving your question,
please click on the thumbs-up vote link, or mark it as accepted
thanks in advance
John
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Matrix Indexing についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!