i am executing the code below and getting the error"Subscript indices must either be real positive integers or logicals"

1 view (last 30 days)
function [z]=decalage(y,h)
[s1,s]=size(h);
[p,p]=size(y);
z(1:s-1,1:s-1)=y((p-s+2):p,(p-s+2):p);
z(s:p,s:p)=y(1:(p-s+1),1:(p-s+1));
z(s:p,1:(s-1))=y(1:p-s+1,p-s+2:p);
z(1:s-1,s:p)=y(p-s+2:p,1:p-s+1);

Accepted Answer

John D'Errico
John D'Errico on 18 Mar 2015
My guess is you are creating a zero or negative index. I cannot know where, since I have no idea what are the sizes of your arrays.
YOU however can find this out easily. First of all, the error should tell you what line it happened in. Is there a reason why you did not bother to give us the complete error message? Must we guess?
Finally, you are the one to fix it, since you are the only one who can run your code. (We don't have those arrays.) Learn to use the debugger. It can show you where the error comes from, as well as allow you to see what those variable sizes were when the error occurred.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!