Plotting Arduino Data in Matlab

i want to generate sine wave in arduino using mathematical sine function and then plot it in MATLAB.
i took help from this link

then i tried my own codes

for arduino

void setup() 
{ Serial.begin(115200); } 
void loop() 
{ 
unsigned a;
a= millis()/10;
float b;
b=sin(a);
Serial.println(b); 
delay(1);
}

For MATLAB i used

s=serial('COM3','BaudRate',115200); 
fopen(s) 
x=1:100; 
n=1; 
while n==1 
   for i=1:length(x) 
       tmp=fscanf(s,'%d'); 
       if length(tmp)>1 
          continue; 
       end 
       y(i)=tmp; 
   end 
     plot(y) 
   drawnow 
   end 
fclose(s)

But i got two problems

  1. MATLAB errors :Series of Warning: Unsuccessful read: Matching failure in format.
    then in the end
    In an assignment A(I) = B, the number of elements in B and I must be the same.

Error in experiemt (line 11)
y(i)=tmp;

  1. The plot i got i got had values of sine as 0, -1 or 1 nothing else

If someone could help
Thanks

layout is important for the readability of code.
removed some code not needed.

void setup() 
{ 
  Serial.begin(115200); 
}
 
void loop() 
{ 
  unsigned long a = millis()/10;
  float b = sin(a);
  Serial.println(b); 
}

The problem is on the receiving end as you need to read digits until you get the CR LF from the arduino.
Now the matlab code just tries to parse the digits that are in the receive buffer, which may not be the complete number. You must also skip the CRLF chars of course...

Fix that and your code will work.

I dnt know CR LF
i shud first look at wat it is, then wud try to figure it again.
thnx

Does it work this way?
CR= start bit
LF= end bit

nd how to i synchronize the receiver (MATLAB) with sender (arduino)

If u modify my code it wud be really appreciable.
THANKS

How to tell MATLAB its the strt of data nd its the end

robtillaart if u can answer this

CRLF = Carriage Return and Line Feed
these are resp. char(13) and char(10)

under windows when you press or these two ASCII codes are used.

You can use them to determine the end of a line.