Find maximum deviation in range of %20 between variables

Viewed 33

How to write a command in Matlab to check the deviation between one variable and others to be within +- %20? as if not in the range would print false if within the range print true

For example, I want to compare R1,R2,R3 with R and should be with the range of plus/minus %20:

R = 0.62
R1 = 0.638
R2 = 0.6337
R3 = 0.6354

Thanks

1 Answers

You want the absolute difference abs(var1-var2) to be smaller than some percentage. You compute the percentage by dividing a piece by the total abs(var1-var2)/var1. This value must be smaller than 0.2, so abs(var1-var2)/var1<0.2

Related