How to display the vector in this question?

Write a function func that will receive one input argument x.
If x is a scalar, the function will return its square root, provided x is non-negative.
If x<0, print an error message: “Error Message: You entered a negative number”.
If x is a vector, the function returns the sum of its components.
If x is a square matrix, the function returns its symmetric part.
If x is a rectangular matrix, the function returns the product of its number of rows and number of columns.

3 Comments

What if x is a square matrix but not symmetric ?
The question does not ask you to display anything, only to return particular values.
Right now I got these typed:
m = input('Enter m: ');
n = randi([1,10]);
%since the question only receive ONE input, the second one can be a random integer
func = m:n
x = func
if m==1 && n==1 % x is scalar
func = sqrt(func);
elseif m<0
disp('Error Message: You entered a negative number')
elseif m==1 && n>1 m>1 && n==1 % x is a vector
func = sum(x);
elseif m==n % x is square matrix
func = flipud(flipplr(x));
else % x is rectangular matrix
numel(x)
end
I believe I did something wrong with the func itself (bold text part), but I don't know how to fix it.

Sign in to comment.

Answers (0)

Asked:

on 31 Oct 2017

Commented:

on 31 Oct 2017

Community Treasure Hunt

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

Start Hunting!