Question 3: Use a single input function to read data from the command window and
ID: 2291473 • Letter: Q
Question
Question 3: Use a single input function to read data from the command window and determine the type of the input. For example, if the user enters his name, a message saying that the input type was string should be displayed (for example: you have entered a positive number). The script should distinguish the following types: Numbers (positive, negative, real and complex) Arrays/Matrices (vectors, 2-D matrices) s Average should have 2 decimal digits to the right of the decimal point and 4 digits to the left matlabExplanation / Answer
------------------------------------------
clc;
d=input('Read data and deterine the type ','s')
[data]=str2double(d)
format short
if (data > 0)
if (imag(data) == 0)
disp('Number is positive and real')
else
disp('Number is positive and real')
end
end
if (data < 0)
if (imag(data) == 0)
disp('Number is negative and real')
else
disp('Number is negative and real')
end
end
%two decimal points
data
%In matlab all the numbers are stored in the form of vectos or matrix. So
%the second point is somewhat invalid. Because if we check for
%isvector(data) or ismatrix(data), it will always give true.
------------------------------------------------------------------------
Try running different input. I have checked with variety of inputs and it works fine.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.