The code works but it gives this warning. How to remove this warning?
3 次查看(过去 30 天)
显示 更早的评论
In the attachment, run the "main.m" file. It works but it continuiusly gives the following warning types:
Warning: Integer operands are required for colon operator when used as index.
> In L2_Array (line 14)
In monoWithArrayByAskic1 (line 9)
In main>@(b)monoWithArrayByAskic1(b,u) (line 16)
In fpa1 (line 36)
In main (line 16)
How to remove these warnings?
0 个评论
采纳的回答
Steven Lord
2023-3-3
Looking at the contents of the attached L2_Array1.m:
textOfFile = readlines('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1313370/L2_Array1.m')
If N is not one more than a multiple of 3, N_on_each_axis is not an integer value. When you use it in constructing the indices into r, those indices aren't integer values and will cause that warning to be issued, the same way the code below does.
x = 1:10;
y = x(2.5:2.5:10)
You probably want to round the indices.
y = x(round(2.5:2.5:10))
更多回答(1 个)
Jan
2023-3-3
You call the function L2_Array in ByAskic.m with the arguments 6 and 10.
Inside L2_Array you calculate
N_on_each_axis = (N-1)/3;
r = zeros(3*N_on_each_axis+1,3);
v = (N_on_each_axis*d:-d:d).';
r(2:N_on_each_axis+1,1) = v;
r(N_on_each_axis+2:2*N_on_each_axis+1,2) = v;
For N=6 and 10, N_on_each_axis is 5/3 and 3. In the first case, this is not an integer and as the error message tells you, this is not valid for indexing. Indices must be positive integers.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!