Simple arithmetic calculation question

1 回表示 (過去 30 日間)
JP
JP 2013 年 6 月 20 日
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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by