Check two string data without carriage return symbol
3 次查看(过去 30 天)
显示 更早的评论
Hi all!
In the serial com port channel values comes from 0 to 1023, this example from Arduino: https://monosnap.com/file/TiTehc6zWhu0zszPnCALbnjIMAfpzf
On the MATLAB side I parse it via function:
while(obj1.BytesAvailable)
Psvoltage = deblank(fscanf(obj1)) %, '%d', 4)
[a, b] = size(Psvoltage)
bb = findstr(Psvoltage, '\r')
if ~isempty(Psvoltage)
sPs = str2num(Psvoltage) * (100 / 1023); %
break;
end
end
But sometimes from serial port I take corrupted data like this: https://monosnap.com/file/ysJFdabTbOVOKoQbgqJYF44SioAORy
And it is cause error in my program:
https://monosnap.com/file/oEJlyjnifsTx6h531xfDi23nQ89Shv
https://monosnap.com/file/6fdI8mgQa6pVjKn2EHFqzXdQnDDLzb
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!
0 个评论
采纳的回答
Ced
2016-3-25
编辑:Ced
2016-3-25
Why not just take the first row?
I.e.
Psvoltage = deblank(fscanf(obj1)) %, '%d', 4)
if ( ~isempty(Psvoltage) )
Psvoltage = Psvoltage(1,:);
end
edit: added ~isempty check
更多回答(1 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!