1
votes

I am trying to plot real time serial values over matlab but i could not succeed it by any demo . My embedded system is already sending data which is checked by serial terminal. When I am trying to get them over matlab there is an error like that :

Warning: Matching failure in format. 
???  In an assignment  A(I) = B, the number of
elements in B and
 I must be the same.

Error in ==> real_time_data_plot at 81 voltage(count) = fscanf(serialObject,'%f');  %#ok<SAGROW>

as a serial in matlab I am using this file : http://www.mathworks.com/matlabcentral/fileexchange/25519-collect-and-plot-data-from-an-instrument-in-real-time in embedded side, I am just sending fixed value which is 100 to reduce the error case probabilities as

sprintf(str,"%d\n",100);
USART_puts(USART2,str); 

The code can plot a couple of samples but a bit later it is crashing with above error notification. Do you have any suggestion ? Thanks

1

1 Answers

1
votes

The error message:

In an assignment A(I) = B, the number of elements in B and I must be the same.

implies that your fscanf(serialObject,'%f') vector is not of the same length as count. If you can examine the output of fscanf(serialObject,'%f') during one such instance you will see this is the case. Assuming count is an integer, it is most likely that serialObject contains more than one element.

An easy work around for this would be along the lines of:

temp = fscanf(serialObject,'%f');voltage(count) = temp(1);

You may wish to use temp(end) if the end value is the one you are interested in.

I'm not familiar with "USART_puts()" but my guess would be that there is some backlog forming, so it is sending more than one update to serialObject once in a while. It may also be sending an empty vector in which case size(temp) would be 0 x 0 which would also result in the error message.