سؤال

Basically i want to send data from the serial port and plot it against the returned data. As each number is sent a response is sent back, so i had the idea of putting scanf in a while loop and running for the number of integers sent. But it only seems to be plotting the last entry. Can anyone help me with this? Are there any other examples like this online?

Also, if i wanted to send a larger string of numbers, say directly from a text file, what function would i use?

s = serial('COM3');
set(s,'BaudRate',9600);
s.InputBufferSize = 6000;
fopen(s);
     t=1;
     a=0;
     x=0;
     fprintf(s,'0 1 2 3 4 5 6 7 8 9')
       while(t<=10)
           a =fscanf(s,'%d');
           t=t+1;
           x =[t a];
         plot(x);
            axis auto;
     grid on;
       end
هل كانت مفيدة؟

المحلول

Try function drawnow after plot. It should refresh the plot each step of the loop.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top