Simple arithmetic calculation question

1 vue (au cours des 30 derniers jours)
JP
JP le 20 Juin 2013
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 commentaires
Jan
Jan le 20 Juin 2013
Looking on incorrect code cannot reveal the intention of the code. Please explain "it isn't working" with any details.
Jan
Jan le 3 Juil 2013
Please answer the question for clarification, delete the question, or post the solution. Thanks.

Connectez-vous pour commenter.

Réponse acceptée

Guru
Guru le 3 Juil 2013
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

Plus de réponses (0)

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by