Instrument Control Toolbox | ![]() ![]() |
Example: Parsing Input Data Using strread
This example illustrates how to use MATLAB's strread
function to parse data that you read from a Tektronix TDS 210 oscilloscope. strread
is particularly useful when you want to parse a string into one or more variables, where each variable has its own specified format.
1. Create an instrument object - Create the GPIB object g
associated with a National Instruments GPIB controller with board index 0, and an instrument with primary address 1.
g = gpib('ni',0,1);
2. Connect to the instrument - Connect g
to the oscilloscope.
fopen(g)
3. Write and read data - Write the ACQUIRE?
command to the instrument using fprintf
, and then read back the result of the command using fscanf
. ACQUIRE?
queries the acquisition parameters and returns the acquisition mode, the number of acquisitions that make up an averaged waveform, the acquisition state (whether it is running or not), and the condition under which the acquisition stops.
fprintf(g,'ACQUIRE?') data = fscanf(g) data = SAMPLE;128;1;RUNSTOP
Use the strread
function to parse and format the data
variable into four new variables.
[mode,navg,state,con] = strread(data,'%s%d%d%s','delimiter',';') mode = 'SAMPLE' navg = 128 state = 1 con = 'RUNSTOP'
4. Disconnect and clean up - When you no longer need g
, you should disconnect it from the instrument, and remove it from memory and from the MATLAB workspace.
fclose(g) delete(g) clear g
![]() | Example: Reading Binary Data | Example: Understanding EOI and EOS | ![]() |