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!