How do I construct this function?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Riyaz Bhayat
am 16 Jan. 2020
Kommentiert: Steven Lord
am 16 Jan. 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 Kommentare
Steven Lord
am 16 Jan. 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.
Akzeptierte Antwort
Allen
am 16 Jan. 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
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!