How can I change values in a table using a function and using the values in the function (if-function)?

I have a column in a table with the variable name footangle (example)
foot angle
-10.55
8.864
-12.801
168.63
-170.196
165.661
-167.901
175.266
12.006
-10.485
Function:
Values greater than 90 Should be subtracted from the value 180. Values smaller than -90 should be added to 180, but keep the minus. All other values are to be maintained.
In other words:
if TableName.footanlge > 90
TableName.footanlge = 180 - footangle
else TableName.footanlge < -90
TableName.footanlge = (-1) * (180 + footangle)
end
How do I adapt the formula so that it works in Mathlab?

 採用された回答

footangle = [-10.55;8.864;-12.801;168.63;-170.196;165.661;-167.901;175.266;12.006;-10.485];
TableName = table(footangle);
TableName.footangle(TableName.footangle>90) = 180 - TableName.footangle(TableName.footangle>90);
TableName.footangle(TableName.footangle<-90) = -180 - TableName.footangle(TableName.footangle<-90);
TableName
TableName = 10×1 table
footangle _________ -10.55 8.864 -12.801 11.37 -9.804 14.339 -12.099 4.734 12.006 -10.485

1 件のコメント

Sabrina
Sabrina 2023 年 7 月 18 日
移動済み: Cris LaPierre 2023 年 7 月 18 日
Thank you- both solution works now- I had just to change footangle:-)
if GaitData.footangle > 90
GaitData.footangle = 180 - GaitData.footangle
else GaitData.footangle < -90
GaitData.footangle = (-1) * (180 + GaitData.footangle)
end
All the best,
Sabrina

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeTables についてさらに検索

製品

リリース

R2023a

質問済み:

2023 年 7 月 17 日

移動済み:

2023 年 7 月 18 日

Community Treasure Hunt

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

Start Hunting!

Translated by