MATLAB Answers

0

When I try to run a function in matlab, I get an error, it is undefined

Asked by Natalie Murawski on 19 Sep 2019 at 22:27
Latest activity Answered by James Tursa
on 19 Sep 2019 at 22:33
I have the following code:
M=[1 2 3; 4 5 6 ; 7 8 9]
function [result] = checkEchelonMatrix(M)
% M - input matrix to test
M=[1 2 3; 4 5 6 ; 7 8 9]
%rest of my code is here
end
When I try to run my function
checkEchelonMatrix(M) I get the following error:
>> matrixcheck(M)
Undefined function or variable 'M'.

  0 Comments

Sign in to comment.

1 Answer

Answer by James Tursa
on 19 Sep 2019 at 22:33
 Accepted Answer

Put this code in a file called checkEchelonMatrix.m that is on the MATLAB path:
function [result] = checkEchelonMatrix(M)
%rest of my code is here
end
Then have other code somewhere else that calls it. E.g., at the command line:
M=[1 2 3; 4 5 6 ; 7 8 9];
checkEchelonMatrix(M);
Do not simply push the "green run" button inside the editor ... that simply runs the code with no inputs.

  0 Comments

Sign in to comment.