Same number of Rows and Cols of a matrix (N*N)

5 ビュー (過去 30 日間)
David Hastana
David Hastana 2020 年 2 月 21 日
コメント済み: Rik 2020 年 2 月 21 日
Hello,
I would like to make a program that requires a matrix A to be square (n*n)
for exmple :
[a,b]=size(A)
if a ~= b
input('Error')
end
Is there a matlab function for this ? without using [a,b]=size(A) ?
Thank you in advance
  1 件のコメント
Rik
Rik 2020 年 2 月 21 日
Backup of question:
Title:
Same number of Rows and Cols of a matrix (N*N)
Body:
Hello,
I would like to make a program that requires a matrix A to be square (n*n)
for exmple :
[a,b]=size(A)
if a ~= b
input('Error')
end
Is there a matlab function for this ? without using [a,b]=size(A) ?
Thank you in advance

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

回答 (2 件)

Stephen23
Stephen23 2020 年 2 月 21 日
編集済み: Stephen23 2020 年 2 月 21 日
This will return false for non-square matrices, and also if ndims>2:
isequal(0,diff(size(M)))
It is easy to use with assert:
assert(isequal(0,diff(size(M))),'Input must be a square matrix')

Matt J
Matt J 2020 年 2 月 21 日
validateattributes(A,"numeric",{"square"})

カテゴリ

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