Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical scalar values.

5 次查看(过去 30 天)
function [y,Err,n] = ARCTANA(x)
[rows,columns]=size(x);
y_plot=zeros(rows,columns);
err_plot=zeros(rows,columns);
n_plot=zeros(rows,columns);
for f=1:rows
for g=1:columns
v=x(f,g);
if v<=-1
N=50;
y=(-pi/2);
for k=0:N
an=((-1)^k)/((2*k+1)*(v^(2*k+1)));
y=y-an;
end
real=atan(v);
Err=abs(real-y);
n=N;
elseif -1<v & v<1
an=v;
y=an;
k=1;
while abs(an)>1E-12
an=(((-1)^k)*v^(2*k+1)/(2*k+1));
y=y+an;
k=k+1;
end
real=atan(v);
Err=abs(real-y);
n=k-1;
else
an=1/v;
y=(pi/2);
k=0;
while abs(an)>1E-12 & k<=50
an=((-1)^k)/((2*k+1)*(v^(2*k+1)));
y=y-an;
k=k+1;
end
real=atan(v);
Err=abs(real-y);
n=k;
end
y_plot(f,g)=y;
y=y_plot;
n_plot(f,g)=n;
n=n_plot
err_plot(f,g)=Err;
Err=err_plot;
end
end
This is the code I wrote
******* GRADING OUTPUT *******
Function name.......CORRECT
inputs.......CORRECT +1 points
outputs.......CORRECT +1 points
Calling function [y, Err, n] = ARCTANA(1 x 1 array)
Grading variable y........correct size +0.5 points
....correct value +0.5 points
Grading variable Err........correct size +0.5 points
....correct value +0.5 points
Grading variable n........correct size +0.5 points
....correct value +0.5 points
Calling function [y, Err, n] = ARCTANA(3 x 5 array)
Grading variable y........correct size +0.5 points
....correct value +0.5 points
Grading variable Err........correct size +0.5 points
....correct value +0.5 points
Grading variable n....Operands to the logical AND (&&) and OR (||) operators must be convertible to logical scalar values. Use the ANY or ALL functions to reduce operands to logical
scalar values.
Error in TestARCTANA
Error in TestARCTANA
Error in TestARCTANA
This is the output of the P-code and I am confused on what is wrong. If I enter a "test" array myself through the function it works just fine.

采纳的回答

Walter Roberson
Walter Roberson 2024-3-14
移动:Walter Roberson 2024-3-14
You would get this error if the grading system is expecting n to be a scalar but n is a 2D array instead.
  6 个评论
Walter Roberson
Walter Roberson 2024-3-18
The grading system contains instructor-written tests for the correctness of variables. The instructor did not think of the possibility that n might not be scalar, and accidentally wrote tests that assume that it is scalar.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by