Matlab rejects string with single quotation even after using strrep
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
dpb
le 4 Déc 2013
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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Entering Commands dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!