Please help with this Ma-tlab question. I am new to this and have no clue what I
ID: 2085547 • Letter: P
Question
Please help with this Ma-tlab question. I am new to this and have no clue what I am doing, if you could post step by step (pictures would be great) guide on how to do this and why you are doing each step that would be great.
Write a MATLAB script which will 1. Prompt the user to enter numerical values one at a time 2. Store those values in memory 3. Ask the user to choose when they are done entering values 4. Plot all entered values as a scatterplot 5. Asks the user if they want to know the average value, and if the user indicates that they do, display the average of all the entered values, and as a bonus, display the maximum and minimum values entered by the userExplanation / Answer
Following is the Matlab Program code. Please go through the program. Every line is described with comment.
Matlab CODE:
clc
clear all
t = 1;
elements = []; % matrix where values will be stored
while(t==1) % while loop to enter data upto required number
elements(end+1) = input('Input a numerical value : '); % Individullay values are entered
prompt = 'Are you done entering (Enter n for no): '; % Ask to more enter
str = input(prompt,'s'); % copy the input value as string
aa = strcmp(str,'n'); % compare for desired condition
if aa ~= 1; % If condition is not satisfied terminate the while loop
t = 0;
end
end
t = 0; % condition to no more while loop
n = linspace(1,length(elements),length(elements)); % creat linear space equal to no of values enterd
scatter(n,elements,'MarkerEdgeColor','b',... % scatter plot for entered values
'MarkerFaceColor','r',...
'LineWidth',1.5)
prompt = 'Do you want average of input values. (Enter y for yes) : '; % ask to average
str1 = input(prompt,'s'); % copy the input variable as string
aa1 = strcmp(str1,'y'); % compare string for apropriate condition
if aa1 == 1
fprintf('Average(Entered Values) = '); % print average value
disp(mean(elements));
fprintf('Minimum Value = '); % print minimum value
disp(min(elements));
fprintf('Maximum Value = '); % print maximum value
disp(max(elements));
end