average - read and count data values compute average print...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
% average.m % (c) 2000 g.m.dick % the purpose of this script is to compute the average of a set of data % values. the number of values is counted until and "end of data" % indication is detected % % data dictionary % variable type description % -------- -------- -------------------------------------------------- % n scalar the number of values to process % i scalar index (subscript) used % - to access vectors % - to count data values % data scalar an input data "buffer" % y vector receives data % sumY scalar the sum of the data % averageY scalar the average of the data % % synopsis % - initialize % - while (more data)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % - read and count data values % - compute average % - print result % clear % initialize - prepare to read 1st datum i = 1; i % read and count data values data = input('Enter datum ("Enter" to stop): '); while ~isempty(data) %data? y(i) = data; % - yes: store i = i+1; % count data = input('Enter datum ("Enter" to stop): '); end e % no more data - compute average sumY = sum(y); % compute sum [dummy, n] = size(y); % determine # values = # columns averageY = sumY/n; a % print result disp(['the average of the 'num2str(n) ' values is ' num2str(averageY)]) d...
View Full Document

This note was uploaded on 04/05/2010 for the course CHEMENG 05078870 taught by Professor Mustafa during the Spring '10 term at Ege Üniversitesi.

Ask a homework question - tutors are online