MATLAB: How to read the whole input buffer of a serial port object

input bufferinputbufferserial

I am communicating with a device via rs-232 and I would like to read the whole iput buffer of the serial object at once.
What I already tried was:
s = serial('com1');
fopen(s);
fscanf(s,'%f',s.bytesavailable);
So when I run the code I only get the last value instead of the whole input buffer.
Do you have a clue what the issue could be?

Best Answer

s = serial('com1');
fopen(s);
data = char(fread(s, s.bytesavailable));
sscanf(data,'%f');
Are you certain that you want to try to read floating point text numbers when the buffer might happen to end in the middle of a number?? For text you normally want to work line-by-line (fgetl() or fgets()) or else fscanf() without a count (allowing the scanning to pause for more characters to be received)