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

조회 수: 1 (최근 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 CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by