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?

 Accepted Answer

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 Comment

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

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2023a

Asked:

on 17 Jul 2023

Moved:

on 18 Jul 2023

Community Treasure Hunt

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

Start Hunting!