我正在尝试计算一次输入一个数据样本的平均值。然后,我将设置一个限制比较的阈值,并仅计算大于阈值的值。然后我会显示小于阈值的值的计数,并计算值的平均值。我的问题是我的平均计算是关闭的,我对解决问题的方法毫无头绪。我写的MATLAB代码如下所示。
%% enter
thresh = input('Please enter the threshold value: ');
datatotal = input('Please enter the number of data samples to be entered: ');
data = input('Please enter a data sample: ');
sum = 0;
count = 1;
while count < datatotal
data = input('Please enter a data sample: ');
if data > thresh
threshdata = data;
for m = 1:threshdata-1
sum = sum + m;
end
end
count = count + 1;
end
average = sum/ length(m);
fprintf('The average of %d valid data samples is %.2f volts.\n', m, average);
% code here