Whats wrong with my code!!!

1 次查看(过去 30 天)
Caitlin
Caitlin 2014-5-3
评论: dpb 2014-5-4
using two arduino megas one 9dof imu and two xbee' to try and write in matlab
this is my code
clc
s = serial('/dev/tty.usbmodem.1411','Baudrate',9600);
fopen('/dev/tty.usbmodem.1411');
disp('Com Port Open')
pause(10);
i = 1;
j=1;
tic
while toc < 15
while(s.bytesavailable>0)
chk = fgetl(s);
if (chk(1) == '!'&& chk(numel(chk)-1)=='f')
disp('data');
out = chk;
xi = findstr(out, '!x');
yi = findstr(out,'!y');
zi = findstr(out,'!z');
ti = findstr(out,'!t');
fi = findstr(out,'!f');
len1 = yi-xi;
len2 = zi-yi;
len3 = ti-zi;
len4 = fi - ti;
for i = 1:1:len1-2
x(i) = out(xi+i+1);
end
xstr = str2num(x);
xnum(j) = xstr;
for i = 1:1:len2-2
y(i) = out(yi+i+1);
end
ystr = str2num(y);
ynum(j) = ystr;
for i = 1:1:len3-2
z(i) = out(zi+i+1);
end
zstr = str2num(z);
znum(j) = zstr;
for i = 1:1:len4-2
t(i) = out(ti+i+1);
end
tstr = str2num(t);
tnum(j) = tstr;
j = j+1;
else
trash = fscanf(s);
end
end
end
fclose(s);
delete(s);
clear s;
plot3(xnum,ynum,znum);grid on;xlabel('roll');ylabel('pitch');zlabel('yaw');
this is the error i receive
Com Port Open usage: numstates = xnum(sys) Error in xnum (line 13) if nargin == 0
Output argument "numstates" (and maybe others) not assigned during call to "/Applications/MATLAB_R2013a.app/toolbox/robust/rctobsolete/mutools/commands/xnum.m>xnum".
Error in letsdowrite (line 56) plot3(xnum,ynum,znum);grid on;xlabel('roll');ylabel('pitch');zlabel('yaw'); >>
I AM VERY MUCH NEW AT THIS so i need some help!
if anyone can help me figure out whats going out that would be fantastic thank you!
Caitlin O'Connor
  1 个评论
dpb
dpb 2014-5-4
...
xnum(j) = xstr;
...
j = j+1;
...
...
end
...
plot3(xnum,ynum,znum);grid on;xlabel('roll');ylabel('pitch');zlabel('yaw');
this is the error i receive
Com Port Open usage: numstates = xnum(sys) Error in xnum (line 13) if nargin == 0
Output argument "numstates" (and maybe others) not assigned during call to "/Applications/MATLAB_R2013a.app/toolbox/robust/rctobsolete/mutools/commands/xnum.m>xnum".
Error in letsdowrite (line 56)
plot3(xnum,ynum,znum);
It appears you have a function file xnum.m as well as having used xnum as an array in your above function. A check at the TMW site doesn't find any reference to xnum so I'm guessing you've inadvertently created this function or have mistakenly used the name of one of your functions twice.
Try clearing all variables and then
which xnum
to see what it resolves to...

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by