HELP, i dont know how to write code for this

조회 수: 4 (최근 30일)
Cooper Jones
Cooper Jones 2021년 5월 6일
댓글: Cooper Jones 2021년 5월 6일
Write a Matlab function that will accept variable number of arguments. If it receives no argument, it will return 'Hello'. If it receives one scalar argument, it will return a structure having one field named 'first' with the value of that scalar argument. If it receives one array, it will return the first column of that array. If it receives two arrays of correct size (same inner dimensions) it will return the product (matrix multiplication) of these arrays, otherwise it returns the product of the top right element of the first array and the bottom right element of the second array. If more than two arguments are received it will return 'unknown case'.
  댓글 수: 2
KSSV
KSSV 2021년 5월 6일
Home work.....what have you attempted?
Cooper Jones
Cooper Jones 2021년 5월 6일
i dont know where to start

댓글을 달려면 로그인하십시오.

답변 (1개)

DGM
DGM 2021년 5월 6일
편집: DGM 2021년 5월 6일
Use varargin, isscalar, ismatrix, etc. This should get you started.
function out = supercoolfunction(varargin)
switch numel(varargin)
case 0
out = 'Why Hello There';
case 1
thisarg = varargin{1};
if isscalar(thisarg)
% assign something to out
elseif ismatrix(thisarg)
% assign something to out
end
case 2
thisarg = varargin{1};
thatarg = varargin{2};
% do something similar here
otherwise
out = 'whatever it''s supposed to say here';
end
Technically, ismatrix() only works on 2D arrays, but I don't think that really matters for this assignment.

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by