??? Index exceeds matrix dimensions. please help me

1 回表示 (過去 30 日間)
matpan community
matpan community 2013 年 3 月 2 日
[m n]=size(handles.data1);%menentukan ukuran citra
for o=1:m
for p=1:n
if o<0
o=1;
end
if p<0
p=1;
end
[d c l]=size(handles.data1);
masuk_enkripsi=double(handles.data1(p:p+d-1,o:o+c-1,:));
??? Index exceeds matrix dimensions.
Error in ==> enkripsi>btn_enkripsi_Callback at 148
masuk_enkripsi=double(handles.data1(p:p+d-1,o:o+c-1,:));
  2 件のコメント
matpan community
matpan community 2013 年 3 月 9 日
it is not Using lowercase and uppercase but "the letter o < the number 0" :)
ChristianW
ChristianW 2013 年 3 月 11 日
What are you trying to do in this line:
masuk_enkripsi=double(handles.data1(p:p+d-1,o:o+c-1,:));

サインインしてコメントする。

採用された回答

ChristianW
ChristianW 2013 年 3 月 2 日
With your image height d and if p gets p=2, then you are trying to address with (p+d-1) the (d+1) pixel. Thats not possible.
  2 件のコメント
matpan community
matpan community 2013 年 3 月 3 日
have a solution?
ChristianW
ChristianW 2013 年 3 月 3 日
Yes, I've got an infinite amount of solutions. I'll rub my crystal ball for visions regarding the purpose of your code.

サインインしてコメントする。

その他の回答 (2 件)

Jan
Jan 2013 年 3 月 4 日
It is confusing to change the loop counter of A FOR loop inside the loop.
Using lowercase and uppercase Oh's as names of variables is confusing also: "if o<0" looks funny, but is to hard to read.
I confirm, that CristianW's answer is exhaustive: Obviously either p+d-1 and/or d+1 exceed the available size. But it is impossible to guess what you want to do instead.
  2 件のコメント
matpan community
matpan community 2013 年 3 月 11 日
it is not Using lowercase and uppercase but "the letter o < the number 0" :)
Walter Roberson
Walter Roberson 2013 年 3 月 11 日
But no explanation for what you think the code should be doing??

サインインしてコメントする。


Walter Roberson
Walter Roberson 2013 年 3 月 11 日
In your line
[m n]=size(handles.data1);%menentukan ukuran citra
you are using size() as if you expect handles.data1 to be two-dimensional. But later you have
[d c l]=size(handles.data1);
which is expecting handles.data1 to be 3 dimensional. If it is 3 dimensional then when you ask for its size() using only two outputs (e.g., [m n]) then size() will set the second output equal to the product of the second and third dimensions -- so although m would be the same as the later d, n would be the product of c and l. This is going to lead to problems when you do your looping over "n" and try to use that value as the index to the second dimension.

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by