Use generic matrix an input into a function in MATLAB

14 ビュー (過去 30 日間)
Xenofon Antoniou
Xenofon Antoniou 2019 年 12 月 6 日
コメント済み: Bhaskar R 2019 年 12 月 6 日
Hi All,
I am trying to write a function that can take any matrix (lets call it x for agruments sake) as input and output a TRUE/FALSE statement.
The context is to check if any of the diagonals in the matrix is a "0" value.
I have tried to do the following:
function DIAG = iszero("insert generic square matrix" ie. x)
DIAG = any(diag(x))
end
The aim is to go to my command window and write:
iszero("insert any matrix from workspace")
For example, if I load a matrix 30x30 called Z1, I want to write:
iszero(Z1) and then give me a logical output.
At the moment with the below is giving me an error.
function DIAG = iszero(x)
DIAG = any(diag(x))
end
"Not enough input arguments.
Error in ppr (line 2)
E = any(diag(x))"
Any assistance is much appreciated.

採用された回答

Bhaskar R
Bhaskar R 2019 年 12 月 6 日
function output = iszero(Z)
output = any(diag(Z) == 0);
end
  2 件のコメント
Xenofon Antoniou
Xenofon Antoniou 2019 年 12 月 6 日
Thanks, this worked in a way opposite to what I wanted by made it work to give a TRUE output if there are no-zero's.
Cheers
Bhaskar R
Bhaskar R 2019 年 12 月 6 日
output = ~any(diag(Z) == 0);

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by