I have been working on this code. But it's kept showing me this error. Please help me

조회 수: 1 (최근 30일)
A = [1 0; -1 3];
n = numposel(A)
function res = numposel(A)
[rows, cols] = size(A);
res = 0;
for i=1:rows
for j =1:cols
if (A(i,j)>0)
res=res+1;
end
end
end
end
Unrecognized function or variable 'numposel'.

채택된 답변

the cyclist
the cyclist 2021년 10월 17일
How are you trying to run that code?
If you just try to run those lines from the Command Window, it will give that error. The reason is that it will try to call the function before it has been defined.
If you put all of that code into an M-file, and then execute the code, it will work.
  댓글 수: 3
the cyclist
the cyclist 2021년 10월 17일
I don't have any experience with MATLAB Grader.
But, you don't really need to define that function, right? It is easy to make that code work directly, without using a function.
Walter Roberson
Walter Roberson 2021년 10월 17일
MATLAB Grader expects a file, if I recall correctly.
And if not, then you can copy and paste all the lines into the MATLAB Grader window. Grader is able to accept "scripts" that include function definitions.

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

추가 답변 (1개)

Cris LaPierre
Cris LaPierre 2021년 10월 18일
You likely just need to enter the function code into MATLAB Grader

카테고리

Help CenterFile Exchange에서 Introduction to Installation and Licensing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by