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

4 vues (au cours des 30 derniers jours)
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 commentaires
Celia
Celia le 13 Mar 2024
Index in position 1 is invalid. Array indices must be positive integers or logical values.
what is wrong please?
Dyuman Joshi
Dyuman Joshi le 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.

Connectez-vous pour commenter.

Réponses (1)

Harald
Harald le 14 Mar 2024
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!