I hate to plow through 2 answers that are clearly not bad, but here the devil is in the details. Yes, you cannot concatenate strings in MATLAB with the +
operator, but the first red flag in your question is that your error message indicates a cell
as one of the arguments to +
. Note that disp
has not even thrown an error at this point, it was +
. This leads me to believe that your code is actually disp('serialPort ' + serialPort);
not disp('serialPort ' + serialPortValue);
since serialPortList
is a cell
array. Was this a typo?
So, by indexing it like serialPort = serialPortList(serialPortValue);
you get a single cell in serialPort
, which would not work with proper string concatenation or disp
. The correction here is to use the curly braces ({}
).
Together with valid string concatenation,
>> serialPort = serialPortList{serialPortValue};
>> disp(['serialPort ' serialPort])
serialPort 'COM3'
The single quotes are in the string because of how you set the strings with set(handles.popupmenuSerialPort,'String',...
, so if you want to strip that, you can use strrep(serialPort,'''','')
.
Note that you can also use fprintf
if you are more comfortable with that style of string formatting.