Real-time plot error on Matlab. HELP!!


rebecca91
03-25-2011, 08:57 AM
Hey guys,

Ive got an arduino plugged into my laptop and connected to my matlab so that i can display 6 outputs coming from my arduino (serial through 1 port)onto a matlab graph.
Im making use of this code but i keep getting the error: "Warning: Matching failure in format." What does this mean?
When i enter the full code my matlab remains on "busy" and my arduino remains on "transmitting" but nothing happens (i dont even see a graph!).

Can you tell me which part of my code needs to be changed please?

SerialPort='com6'; %serial port
MaxDeviation = 3; %Maximum Allowable Change from one value to next
TimeInterval=0.2; %time interval between each input.
loop=120; %count values

%%Set up the serial port object
s = serial(SerialPort)
fopen(s);
time =now;
voltage = 0;

%% Set up the figure
figureHandle = figure('NumberTitle','off',...
'Name','Voltage Characteristics',...
'Color',[0 0 0],'Visible','off');

% Set axes
axesHandle = axes('Parent',figureHandle,...
'YGrid','on',...
'YColor',[0.9725 0.9725 0.9725],...
'XGrid','on',...
'XColor',[0.9725 0.9725 0.9725],...
'Color',[0 0 0]);
hold on;
plotHandle = plot(axesHandle,time,voltage,'Marker','.','LineWid th',1,'Color',[0 1 0]);
xlim(axesHandle,[min(time) max(time+0.001)]);

% Create xlabel
xlabel('Time','FontWeight','bold','FontSize',14,'C olor',[1 1 0]);
% Create ylabel
ylabel('Voltage in V','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create title
title('Real Time Data','FontSize',15,'Color',[1 1 0]);
%% Initializing variables
voltage(1)=0;
time(1)=0;
count = 2;
k=1;
while ~isequal(count,loop)

%%Re creating Serial port before timeout
k=k+1;
if k==25
fclose(s);
delete(s);
clear s;
s = serial('com6');
fopen(s)
k=0;
end

%%Serial data accessing
//I THINK MY ERROR LIES SOMEWHERE HERE
invalues = fscanf(s,'%f');
for k= 1 : length(invalues)
voltage(count) = invalues(k);
if voltage(count)-voltage(count-1) > MaxDeviation
voltage(count) = voltage(count-1)
end
time(count) = count;
count = count + 1;
end
set(plotHandle,'YData',voltage,'XData',time);
pause(TimeInterval);
end

Thanks for any help!

rebecca91
03-26-2011, 09:10 AM
Anybody?? Please help!

William Handler
04-15-2011, 11:14 AM
The forum you posted on is about using numerical recipes code in the matlab environment, you will get useful responses on a mathworks forum I guess.