fscanf read multiple data

Hi everybody,
I have a matlab program in which I can read distance data from an Arduino. I received them over Bluetooth. I use fscanf function to read but now I want to read the number of sample and distance as follows:
N.sample (tab) distance
How could I do it? Thank you

Respuestas (1)

Santhana Raj
Santhana Raj el 30 de Mzo. de 2017

0 votos

Modify the fscanf command's formatspec, the 2nd variable to include two float variables.
Ex: A=fscanf(fileid, '%f %f',[Inf,2]);
hope it helps

3 comentarios

Itziar Uzqueda
Itziar Uzqueda el 30 de Mzo. de 2017
I get this error when trying this
Error using icinterface/fscanf (line 171)
SIZE cannot be set to INF.
So...it's not working
Jan
Jan el 30 de Mzo. de 2017
Editada: Jan el 30 de Mzo. de 2017
[Inf, 2] is not allowed, but [2, Inf] is for fscanf with files. This reads the datauntil the end of file. But your Arduino has no end. Then please replace the size according to your needs.
Itziar Uzqueda
Itziar Uzqueda el 27 de Abr. de 2017
I see your point but...any idea of how I can do that? because I receive data until I press the STOP button

Iniciar sesión para comentar.

Etiquetas

Preguntada:

el 30 de Mzo. de 2017

Comentada:

el 27 de Abr. de 2017

Community Treasure Hunt

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

Start Hunting!

Translated by