Simple arithmetic calculation question

1 次查看(过去 30 天)
Hey just had an easy question that I cant seem to solve. Basically this is what I want to do, but it isnt working... (I think you get the gist of what Im trying to do by looking at the incorrect code)
datastr='0201+03158+04424-06291+05555-004556+003275-090965+014850000003100011F39 02+00364+01836-02658+09456+020408+000839-093108+019160000003100011F39 00004CE4'
data.Q0=str2double(datastr(5:10))/10000;
data.Qx=str2double(datastr(11:16))/10000;
data.Qy=str2double(datastr(17:22))/10000;
data.Qz=str2double(datastr(23:28))/10000;
data.Tx=str2double(datastr(29:35))/100;
data.Ty=str2double(datastr(36:42))/100;
data.Tz=str2double(datastr(43:49))/100;
data.Q02=str2double(((datastr(75:80))/10000)) - data.Q0;
data.Qx2=str2double(((datastr(81:86))/10000)) - data.Qx;
data.Qy2=str2double(((datastr(87:92))/10000)) - data.Qy;
data.Qz2=str2double(((datastr(93:98))/10000)) - data.Qz;
data.Tx2=str2double(((datastr(99:105))/100)) - data.Tx;
data.Ty2=str2double(((datastr(106:112))/100)) - data.Ty;
data.Tz2=str2double(((datastr(113:119))/100)) - data.Ty;
  3 个评论
Jan
Jan 2013-6-20
Looking on incorrect code cannot reveal the intention of the code. Please explain "it isn't working" with any details.
Jan
Jan 2013-7-3
Please answer the question for clarification, delete the question, or post the solution. Thanks.

请先登录,再进行评论。

采纳的回答

Guru
Guru 2013-7-3
Well the error is pretty obvious. The following lines is using parenthesis incorrectly:
data.Q02=str2double(((datastr(75:80))/10000)) - data.Q0;
data.Qx2=str2double(((datastr(81:86))/10000)) - data.Qx;
data.Qy2=str2double(((datastr(87:92))/10000)) - data.Qy;
data.Qz2=str2double(((datastr(93:98))/10000)) - data.Qz;
data.Tx2=str2double(((datastr(99:105))/100)) - data.Tx;
data.Ty2=str2double(((datastr(106:112))/100)) - data.Ty;
data.Tz2=str2double(((datastr(113:119))/100)) - data.Ty;
You want to place your parenthesis so str2double operates only on the datastr() and not the divide by.
data.Q02=str2double(datastr(75:80))/10000 - data.Q0;
data.Qx2=str2double(datastr(81:86))/10000 - data.Qx;
data.Qy2=str2double(datastr(87:92))/10000 - data.Qy;
data.Qz2=str2double(datastr(93:98))/10000 - data.Qz;
data.Tx2=str2double(datastr(99:105))/100 - data.Tx;
data.Ty2=str2double(datastr(106:112))/100 - data.Ty;
data.Tz2=str2double(datastr(113:119))/100 - data.Ty;
HTH

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by