User`s manual

Writing and Reading Data
8-39
Note that for a given read operation, you may not know the number of bytes
returned by the device. Therefore, you may need to preset the
InputBufferSize property to a sufficiently large value before connecting the
serial port object.
As shown below, after the data is stored in the input buffer, it is then
transferred to the output variable specified by
fscanf.
Reading Text Data
You use the fgetl, fgets, and fscanf functions to read data from the device,
and format the data as text.
For example, suppose you want to return identification information for the
oscilloscope. This requires writing the
*IDN? command to the instrument, and
then reading back the result of that command.
s = serial('COM1');
fopen(s)
fprintf(s,'*IDN?')
out = fscanf(s)
out =
TEKTRONIX,TDS 210,0,CF:91.1CT FV:v1.16 TDS2CM:CMV:v1.04
By default, fscanf reads data using the %c format since the data returned by
many serial port devices is text based. However, you can specify many other
formats as described in the
fscanf reference pages.
out=fscanf(s)
...
MATLABInput Buffer
Bytes used during read
Bytes unused during read
data