~~~~~~~~~Please use MATLAB to answer the following questions and provide input a
ID: 3814373 • Letter: #
Question
~~~~~~~~~Please use MATLAB to answer the following questions and provide input and outputs. Thanks!~~~~~~~~~~
3. Write a MATLAB program (numbers) using a for loop to determine the number of values that are positive, the number of values that are negative. You program counts a zero as a negative number. Prompt the user to enter the vector of values and then display the number of positive, and negative values. Example for function numbers numbers Enter the vector of values -23 -33 9 3 23 23 66 -22 0 0 22 8] The number of positive numbers in V are 7 The number of negative numbers in V are 5 Run your program with v 125: 0.3:111Explanation / Answer
Ans:
matlab program with comments(%):
%print( enter values user input)
sprintf('Enter elements of vector');
% after enterng 'v' run the below_code
%for loop length
for i = 1:length(v)
%if cond
if v(i) > 0
%prints
sprintf('v(%i)>0',i)
%elseif less than 0
elseif v(i) <0
%printf
sprintf('v(%i)<0',i)
%else
else
%prints equals 0
sprintf('v(%i)=0',i)
%end
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.