I am trying to create a function that checks whether an element is a matrix or a vector.
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Connor Mondock
le 3 Fév 2022
Commenté : Davide Masiello
le 4 Fév 2022
I am trying to create a function that checks whether an element is a matrix or a vector. If it is a vector, it should return an error. If it is a matrix, it should check whether it is tall, square, or wide. I really don't have any start to this since I am very new to MATLAB.
0 commentaires
Réponse acceptée
Davide Masiello
le 3 Fév 2022
Try with this:
function checkSize(A)
[m,n] = size(A);
if m == 1 || n == 1
error('Input is a vector')
else
if m > n
fprintf('Matrix is tall\n')
elseif m < n
fprintf('Matrix is wide\n')
else
fprintf('Matrix is square\n')
end
end
end
Please note that there are a number of ways this could have been done, the example above is just the quickest I could think of.
2 commentaires
Davide Masiello
le 4 Fév 2022
No problem. If you don't have any other question, please accept the answer.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!