isDone

Tests whether a System object has finished producing data.

Category: Programming > Classes

Syntax

tf = isDone(obj)

Returns true when a source System object has no more data to give.

Description

Source objects deliver their data in blocks, one call at a time. The standard loop reads a block and checks isDone before reading the next: while ~isDone(src), block = src(); ... end. The check is false until the final block has been delivered.

A System object that never ends, such as a signal generator, reports false forever, so the loop needs another stop condition.

Input arguments

obj
A System object that implements isDone, typically a data source such as a file reader.

Output arguments

tf
true after the last block has been read.

Example

The same loop pattern with a plain counter

data = reshape(1:10, 5, 2);
k = 0;
while k < size(data, 2)
  k = k + 1;
  block = data(:, k);
  fprintf('block %d sums to %d\n', k, sum(block))
end
Output
block 1 sums to 15
block 2 sums to 40

Notes

System objects are not available in MatLivre, so isDone cannot be called. The example reproduces the read-until-done pattern with a counter.

See also

isLocked clone feof