Index in position 1 is invalid. Array indices must be positive integers or logical values.
Show older comments
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 Comments
Celia
on 13 Mar 2024
Dyuman Joshi
on 13 Mar 2024
"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.
Answers (1)
Harald
on 14 Mar 2024
0 votes
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!