How do you take a set of values in a matrix and normalize them to a 360 degree rotation?

2 ビュー (過去 30 日間)
Philip Edwards
Philip Edwards 2023 年 7 月 5 日
回答済み: Daniel 2023 年 7 月 6 日
I have a digital trigger variable that displays a 1 value at the bottom position and a 0 value at every other position. How do I make a loop that places these values from 0 degrees to 360 degrees? I am sorry if this is vague.
  1 件のコメント
Anton Kogios
Anton Kogios 2023 年 7 月 5 日
Your question is quite vague. If your variable is just 1s and 0s, and you want to convert it to 360s and 0s, you could just multiply it by 360. Or rescale may be what you are looking for.

サインインしてコメントする。

回答 (1 件)

Daniel
Daniel 2023 年 7 月 6 日
Am I right in thinking you would want to do something like this?
[1 0 0 0 1 0 0 0 1] -> [0 90 180 270 0 90 180 270 0]
or
[1 0 1 0 1 0 1 0 1] -> [0 180 0 180 0 180 0 180 0]
You'll need some kind of counter to identify the distance between successive nonzero values; between any two nonzero values you can just interpolate from 0 to 360. The catch is that since your sensor only reads 0's and 1's, you can't interpolate properly until you have the next 1 to reference to.
You can identify all the nonzero locations with find.
vals = [0 1 0 0 0 1 0 0 0 1 0];
idxs = find(vals)
idxs = 1×3
2 6 10
Then you can interpolate, e.g., to run from 0 to 360 between 2 and 6 you could use linspace.
interpolatedVals = vals;
interpolatedVals(idxs(1):idxs(2)) = linspace(0,360,idxs(2)-idxs(1)+1)
interpolatedVals = 1×11
0 0 90 180 270 360 0 0 0 1 0
And loop that from the idx(1):idx(2) range up to idx(end-1):idx(end).
This won't help you resolve the assumed angles before your first 1 or after your last 1, of course, since you don't have any known average angular velocity in those regions.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

タグ

製品


リリース

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by