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

1 回表示 (過去 30 日間)
Natalie Murawski
Natalie Murawski 2019 年 9 月 19 日
回答済み: James Tursa 2019 年 9 月 19 日
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'.

採用された回答

James Tursa
James Tursa 2019 年 9 月 19 日
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 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by