type if x is a square matrix statement
28 ビュー (過去 30 日間)
古いコメントを表示
Hi, How do I write the script for "If x is a square matrix funcz will be the 0"?
Thanks!
1 件のコメント
Jan
2017 年 10 月 27 日
A bullet-proof solution is not trivial. Therefore this question is more interesting than it looks like on first glance.
回答 (3 件)
Jan
2017 年 10 月 26 日
編集済み: Jan
2017 年 10 月 26 日
funcz = ~ismatrix(x) || (size(x, 1) ~= size(x, 2));
or with Matlab versions before R2010b:
funcz = (ndims(x) ~= 2) || (size(x, 1) ~= size(x, 2));
This rejects [0 x 1] matrices, but is is questionable, if an empty matrix can be non-square.
To reply funcz=0 for vectors:
funcz = (ndims(x) ~= 2) || all(size(x) ~= 1);
or with modern Matlab versions:
funcz = ~isvector(x)
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Classification Trees についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!