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 CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by