MATLAB Answers


Check two string data without carriage return symbol

Asked by Sergey Makovkin on 25 Mar 2016
Latest activity Edited by Ced
on 25 Mar 2016
Hi all!
In the serial com port channel values comes from 0 to 1023, this example from Arduino:
On the MATLAB side I parse it via function:
Psvoltage = deblank(fscanf(obj1)) %, '%d', 4)
[a, b] = size(Psvoltage)
bb = findstr(Psvoltage, '\r')
if ~isempty(Psvoltage)
sPs = str2num(Psvoltage) * (100 / 1023); %
But sometimes from serial port I take corrupted data like this:
And it is cause error in my program:
This is two string data, but without carriage return symbol, because all checking such as: ~isnan(), ~isempty() and findstr(Psvoltage, '\r') this data had been passed.
The question is: how do I check these data would be to ignore them?
Thank you!


Sign in to comment.

2 Answers

Answer by Ced
on 25 Mar 2016
Edited by Ced
on 25 Mar 2016
 Accepted Answer

Why not just take the first row?
Psvoltage = deblank(fscanf(obj1)) %, '%d', 4)
if ( ~isempty(Psvoltage) )
Psvoltage = Psvoltage(1,:);
edit: added ~isempty check


I tried you case, but it dont solve my problem with corrupted data. This is the code:
This is corrupted case with errors:
How about
Psvoltage = deblank(fscanf(obj1)) %, '%d', 4)
if ( ~isempty(Psvoltage) )
volt_num = str2num(Psvoltage);
Psvoltage = volt_num(1);
or simply < removed, did not work >, see Sergey's answer below.

Sign in to comment.

Answer by Sergey Makovkin on 25 Mar 2016

Thank you very much! First variant is working correctly, but second is not (please see the 2nd result:

  1 Comment

Interesting, thanks for testing them out!

Sign in to comment.