(Matlab Script Help) (Please include comment% to explain the steps of the codes,
ID: 3853679 • Letter: #
Question
(Matlab Script Help)
(Please include comment% to explain the steps of the codes, thank you)
for example,
The arrays PriceA, PriceB, and PriceC are given below and contain stock prices over 10 days. Use MATLAB to determine how many days the price of stock A was above both the price of stock B and the price of stock C.
PriceA = [19, 18, 22, 21, 25, 19, 17, 21, 27, 29]
PriceB = [22, 17, 20, 19, 24, 18, 16, 25, 28, 27]
PriceC = [17, 13, 22, 23, 19, 17, 20, 21, 24, 28]
Write a MATLAB script to determine how many days the price of stock A was above either the price of stock B or the price of stock C, but not both.
%A matlab code is written to find the number of days the %price of stock A, is greater than price of stock B, and %price of stock as per the given conditions and the %results are displayedExplanation / Answer
Stock1 = [19 18 22 21 25 19 17 21 27 29];
Stock2 = [22 17 20 19 24 18 16 25 28 27];
Stock3 = [17 13 22 23 19 17 20 21 24 28];
%Determines how many days the price of stock1 was above the prices of both
%stock 2 and stock 3.
[temp, output1] = size(Stock1(Stock1 > Stock2 & Stock1 > Stock3));
fprintf('The number of days Stock1 greater than both Stock2 and Stock3 is %d. ', output1);
%Determines how many days the price of stock1 was above the price of stock 2.
[temp, output2] = size(Stock1(Stock1 > Stock2));
fprintf('The number of days Stock1 greater than Stock2 is %d. ', output2);
%Determines how many days the price of stock1 was above the price of stock 3.
[temp, output3] = size(Stock1(Stock1 > Stock3));
fprintf('The number of days Stock1 greater than Stock3 is %d. ', output3);
%Determines how many days the price of stock A was above either the price of
%stock B or the price of stock C, but not both.
fprintf('The number of days Stock1 greater than either Stock2 or Stock3 but not both is: %d. ', output1 + output2 - output3);
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.