User`s manual
8 Serial Port I/O
8-26
Creating an Array of Serial Port Objects
In MATLAB, you can create an array from existing variables by concatenating
those variables together. The same is true for serial port objects. For example,
suppose you create the serial port objects
s1 and s2
s1 = serial('COM1');
s2 = serial('COM2');
You can now create a serial port object array consisting of s1 and s2 using the
usual MATLAB syntax. To create the row array
x
x = [s1 s2]
Instrument Object Array
Index: Type: Status: Name:
1 serial closed Serial-COM1
2 serial closed Serial-COM2
To create the column array y
y = [s1;s2];
Note that you cannot create a matrix of serial port objects. For example, you
cannot create the matrix
z = [s1 s2;s1 s2];
??? Error using ==> serial/vertcat
Only a row or column vector of instrument objects can be created.
Depending on your application, you may want to pass an array of serial port
objects to a function. For example, to configure the baud rate and parity for
s1
and
s2 using one call to set
set(x,'BaudRate',19200,'Parity','even')
Refer to the serial port function reference to see which functions accept a serial
port object array as an input.