Documente Academic
Documente Profesional
Documente Cultură
Machine
5 (Loops and Functions) Score
Problem #
Name Anagaran, Hector II, C. Section
A11
1. soundsignal.m
Command Window:
a)
>> soundsignal
Please enter the threshold below which samples will be considered to be invalid:0.10
Please enter the number of data samples to be entered:5
Please enter a data sample:2.0
Please enter a data sample:1.9
Please enter a data sample:1.0
Please enter a data sample:1.8
Please enter a data sample:0.1
The average of 5 valid data samples is 1.36 volts.
b) >> soundsignal
Please enter the threshold below which samples will be considered to be invalid:10.0
Please enter the number of data samples to be entered:5
Please enter a data sample:2.0
Please enter a data sample:1.9
Please enter a data sample:1.0
Please enter a data sample:1.8
Please enter a data sample:0.1
There are no valid data sample.
Script:
%The script calculates the average of the valid data.
threshold=input('Please enter the threshold below which
samples will be considered to be invalid:');
N=input('Please enter the number of data samples to be
entered:');
data=zeros(1,N);
for i=1:N
data(i)=input('Please enter a data sample:');
end
k=1;
for i=1:N
if data(i)>=threshold
validdata(k)=nonzeros(data(i));
k=k+1;
elseif data(i)<threshold
invaliddata(k)=(data(i));
k=k+1;
numbers=nonzeros(invaliddata);
invalidnumber=length(numbers);
for i=1
if 0<invalidnumber && invalidnumber==5
numbers=nonzeros(invaliddata);
invalidnumber=length(numbers);
disp('There are no valid data sample.')
end
end
end
end
for i=1
if 0<validnumber
fprintf('The average of %d valid data
samples is %.2f volts.\n',validnumber,average);
end
end
count = 0;
while any(strcmp(alphabet,letter))
count = count + 1;fprintf('Thanks, you have entered letter %s\n',
ans =
ans =
2 4
ans =
3 6 9
ans =
4 8 12 16
ans =
5 10 15 20 25
ans =
6 12 18 24 30 36
ans =
7 14 21 28 35 42 49
ans =
8 16 24 32 40 48 56 64
ans =
Columns 1 through 8
Column 9
81
Script:
function multimesa(N)
%This funtion prints a multiplication table based on
generated numbers
for i=1:N
linspace(i,i*i,i)
end