Borrar filtros
Borrar filtros

How do I construct this function?

1 visualización (últimos 30 días)
Riyaz Bhayat
Riyaz Bhayat el 16 de En. de 2020
Comentada: Steven Lord el 16 de En. de 2020
I am in need of some help regarding this question,
Write a function Matrix Count(matrix) that has as input a matrix and has as output a string If the matrix is not square, the output string is 'this is not a square matrix'. If the matrix is square, the output string is 'this matrix has determinant ??'
Any guidance would be very much appreciated
Thanks
  2 comentarios
Spencer Chen
Spencer Chen el 16 de En. de 2020
Do you know how to check the size of a matrix?
Steven Lord
Steven Lord el 16 de En. de 2020
This sounds like a homework assignment. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
If you aren't sure where to start because you're not familiar with how to write MATLAB code, I suggest you start with the MATLAB Onramp tutorial (https://www.mathworks.com/support/learn-with-matlab-tutorials.html) to quickly learn the essentials of MATLAB.

Iniciar sesión para comentar.

Respuesta aceptada

Allen
Allen el 16 de En. de 2020
The following should accomplish what you are asking.
function TF = issquare(A)
% Verifies that A is a numerical matrix with more that one element (ie - scalar).
if isnumeric(A) && ismatrix(A) && numel(A)>1
% Get the size (rows & columns) of A
sz = size(A); % sz(1)==# of rows and sz(2)==# of columns
if isequal(sz(1),sz(2))
TF = 'this matrix has determinant';
% Would recommend making TF a boolean instead of a message (ie - true/false)
% TF = true;
else
TF = 'this is not a square matrix'
% Would recommend making TF a boolean instead of a message (ie - true/false)
% TF = false;
end
else % Input is either a scalar value, non-numeric, and/or is not a matrix.
error('Invalid Input: Must be a numerical, non-scalar, matrix.')
end
end

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by