whileDataFailToRead - fprintf%d data values were read and...

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

View Full Document Right Arrow Icon
% whileDataFailToRead.m % (c) 2001 g.m.dick % the purpose of this script is to demonstrate: % - a useful approach to reading an unknown number of data values % - a simillar approach that fails - i've not fully investigated % but you should be aware of this EviL approach % % this works nicely % ================= clear; c data = input('Enter: '); % read 1st value i = 1; % initialize pointer i while ~isempty(data); % is there data? x(i) = data; % - yes: store it i = i + 1; % increment pointer data = input('Enter: '); % read next input end e [dummy, n] = size(x); % - no: extract number of values read
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: fprintf('%d data values were read and stored in the vector ''x''.\n', n); fprintf('Press any key to continue.\n\n'); pause; p % this fails - but it sure looks like it should work . .. % ====================================================== % clear; c i = 1; x(i) = input('Enter: '); x while ~isempty(x(i)); i = i + 1; x(i) = input('Enter: '); % the problem lies hear - when input is null end % ------------------------------------------e [dummy, n] = size(x); fprintf('%d data values were read and stored in the vector ''x''.\n', n);...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online