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.
  댓글 수: 2
Walter Roberson
Walter Roberson 2024년 3월 14일
n_plot(f,g)=n;
n=n_plot
That is suspicious, that you are returning a 2 d array for n.
Catalytic
Catalytic 2024년 3월 14일
I highly recommend against "f" and "g" as symbols for loop indices. It is terribly unreadable to others -
for f=1:rows
for g=1:columns

댓글을 달려면 로그인하십시오.

채택된 답변

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.
Sal
Sal 2024년 3월 19일
Ok seems like something to talk to the proffesor about, thanks.

댓글을 달려면 로그인하십시오.

추가 답변 (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