loops performed on table

조회 수: 1 (최근 30일)
Phoebe Armitage
Phoebe Armitage 2021년 3월 4일
답변: David Hill 2021년 3월 4일
TT =
3587×5 table
Angle Speed theta x speed y speed
_____ _____ _____ _______ _______
199 0.119 NaN NaN NaN
209 0.214 NaN NaN NaN
210 0.238 NaN NaN NaN
201 0.191 NaN NaN NaN
I would like to process the following actions:
For rows where 0<=angle<90 --> theta=angle
yspeed=speed*cos(theta)
xspeed=speed*sin(theta)
For rows where 90<=angle<180 --> theta=angle-90
yspeed=speed*sin(theta)
xspeed=speed*cos(theta)
For rows where 180<=angle<270 --> theta=angle-180
yspeed=speed*cos(theta)
xspeed=speed*sin(theta)
For rows where 270<=angle<0 --> theta=angle-270
yspeed=speed*sin(theta)
xspeed=speed*cos(theta)
How would I code this?
Many thanks
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2021년 3월 4일
hello
well, you have almost the code ready when you wrote the question,
where do you have trouble with ?

댓글을 달려면 로그인하십시오.

답변 (1개)

David Hill
David Hill 2021년 3월 4일
idx=TT.Angle>=0&TT.Angle<90;
TT.theta(idx)=TT.Angle(idx);
TT.yspeed(idx)=TT.Speed(idx).*cosd(TT.theta(idx));
TT.xspeed(idx)=TT.Speed(idx).*sind(TT.theta(idx));%continue in the way for the others

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by