필터 지우기
필터 지우기

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 CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by