%% Write to a Characteristic on a Bluetooth Low Energy Peripheral Device
% Write data to a characteristic on a Bluetooth Low Energy Peripheral Device.
% Create a connection to a nearby Bluetooth Low Energy peripheral device.

b = ble("DemoDevice")

% Create a characteristic object that represents the "Gender" characteristic.

c = characteristic(b,"User Data","Gender")

% Because this characteristic is readable and writable, you can write data to it and verify the change in values. Use read to get the latest data.

data = read(c)

% Interpret the data by referring to the specification for this characteristic on the Bluetooth SIG website. 0 represents male and 1 represents female. Write 1 to the characteristic to indicate female.

write(c,1)

% You can read from the characteristic again to observe the change in the data.

data = read(c)

% Copyright 2019 The MathWorks, Inc.