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

2 visualizaciones (últimos 30 días)
David Hastana
David Hastana el 21 de Feb. de 2020
Comentada: Rik el 21 de Feb. de 2020
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 comentario
Rik
Rik el 21 de Feb. de 2020
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

Iniciar sesión para comentar.

Respuestas (2)

Stephen23
Stephen23 el 21 de Feb. de 2020
Editada: Stephen23 el 21 de Feb. de 2020
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 el 21 de Feb. de 2020
validateattributes(A,"numeric",{"square"})

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by