Matlab rejects string with single quotation even after using strrep

조회 수: 1 (최근 30일)
Matuno
Matuno 2013년 12월 4일
댓글: Matuno 2013년 12월 4일
I am working with serial port and a simple GUI to send a particular string to the serial port. The value will change the destination address for Xbee. The code in a simpler way is like this:
s = serial ('COM6'); % the communication port
fopen(s); %open the serial port
set(s,'terminator','CR');
TxTex = get(handles.destAddMSB, 'string');%destAddMSB is a Edit text box in GUI where I am %inputting a string
disp(TxTex);
msb = strcat('ATDH', TxTex);
fwrite(s,'+++');
pause(1);
status = fscanf(s);
index=strfind(status,'OK');
fprintf(s,'%s',msb);
pause(0.1);
The Error message Matlab is showing:
The third input argument must be a string.
whereas the third input is msb in above mentioned code. I tried it otherway like sending only a string instead of msb and it is working ok. The main problem is when I am displaying msb it is showing in a single quotation [e.g. 'ATDH13A200']. Whereas for successful case there should not be any single quotation [i.e. ATDH13A200]. I have tried to use strrep(msb, char(39), ''); but it shows the same quotation mark. Could anyone please let me know how to accomplish this task so that the msb would work like a real string without the quotation marks?

채택된 답변

dpb
dpb 2013년 12월 4일
The single quotes when displaying a variable indicate the content of a cell array containing a character variable, not a character variable itself. Note the following demonstration--
>> s='ATHD'
s =
ATHD
>> s={'ATHD'}
s =
'ATHD'
>> char(s)
ans =
ATHD
>>
The answer is to use char to cast the the cell to the character string. Or, you can write
msb{:}
using the curlies to dereference the cell instead.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Entering Commands에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by