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

5 views (last 30 days)
Manh Duc Luong
Manh Duc Luong on 17 Oct 2021
Commented: Manh Duc Luong on 19 Oct 2021
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)
Unrecognized function or variable 'numposel'.

Answers (2)

the cyclist
the cyclist on 17 Oct 2021
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.
Walter Roberson
Walter Roberson on 17 Oct 2021
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.

Sign in to comment.


Community Treasure Hunt

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

Start Hunting!

Translated by