Index in position 1 is invalid. Array indices must be positive integers or logical values.

4 次查看(过去 30 天)
function Out = RotationAlpha (In,deg)
[m,n]=size(In);
M=round(abs(n*sind(deg))+abs(m*cosd(deg)));
N=round(abs(m*sind(deg))+abs(n*cosd(deg)));
B=zeros(M,N,'uint8');
R=[abs(cosd(deg)),abs(sind(deg));abs(-sind(deg)),abs(cosd(deg))];
for x=1:m
for y= 1:n
i=x-m/2;
j=y-n/2;
D=R.*[i,j];
xn= round(D(1)) + round(M/2)
yn= round(D(2)) + round(N/2)
B(xn,yn) = In(i,j);
end
end
  2 个评论
Celia
Celia 2024-3-13
Index in position 1 is invalid. Array indices must be positive integers or logical values.
what is wrong please?
Dyuman Joshi
Dyuman Joshi 2024-3-13
"what is wrong please?"
For the given input you have provided, either i or j (or both), which you are using as indices to In, are not positive integers.
Also, i and j are pre-defined to be the imaginary unit (i.e. square root of -1) in MATLAB, so (over-writing and) using them as indices is not generally suggested. You might want to change the name of the variables to avoid confusion.

请先登录,再进行评论。

回答(1 个)

Harald
Harald 2024-3-14
Hi,
when encountering problems with functions, please also provide the inputs you used for calling the function.
Here, the function will fail if the number of rows or columns of In are odd since, as Dyuman writes, this will result in non-integer indices.
Also, observe the warnings provided by the Code Analyzer. Aside of missing semicolons, the output argument Out is not assigned.
Best wishes,
Harald

Community Treasure Hunt

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

Start Hunting!