How do I construct this function?

1 回表示 (過去 30 日間)
Riyaz Bhayat
Riyaz Bhayat 2020 年 1 月 16 日
コメント済み: Steven Lord 2020 年 1 月 16 日
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 件のコメント
Spencer Chen
Spencer Chen 2020 年 1 月 16 日
Do you know how to check the size of a matrix?
Steven Lord
Steven Lord 2020 年 1 月 16 日
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.

サインインしてコメントする。

採用された回答

Allen
Allen 2020 年 1 月 16 日
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 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by