Effacer les filtres
Effacer les filtres

How to filter a datasheet?

2 vues (au cours des 30 derniers jours)
Jasraj Soni
Jasraj Soni le 10 Sep 2019
Commenté : Jasraj Soni le 10 Sep 2019
I have imported a datasheet from excel in the form of table (130 * 23).
Each column represents a design parameter of robotic actuator (i.e. Continuous Torque, Speed, weight, Reduction ratio, etc.)
I want to filter my table based on some constraints like, I want to extract only those rows where torque value is between 1 to 5 and weight value is between 0 to 1 and so on.
For that I wrote this:
FinalTable = compileddatasheet((compileddatasheet.ContinuousTorqueNm > 1) & (compileddatasheet.ContinuousTorqueNm < 5) & (compileddatasheet.Weightkg > 0) & (compileddatasheet.Weightkg < 1), :);
This code works fine.
But,
Now I want to add one more constraint, see the code below
FinalTable = compileddatasheet(a*(compileddatasheet.ContinuousTorqueNm > 1) & b*(compileddatasheet.ContinuousTorqueNm < 5) & c*(compileddatasheet.Weightkg > 0) & d*(compileddatasheet.Weightkg < 1), :);
As you can see in the above code i added 4 binary variables (a,b,c,d) which can be either 0 or 1.
I added these variables so I can decide whether I want to use the particular constraint or not based on its value (i.e. if a = 0 and other variables are still 1, results will be shown based on only three constraints).
So my approach here is wrong because its not showing the true results.
So it would be of great help if anyone could help me out here with a proper approach.
Thank you.

Réponse acceptée

Walter Roberson
Walter Roberson le 10 Sep 2019
Each time you set one of the binary variables to 0, then 0*(the logical value of the expression next to it) is going to be 0, which is false, and expression & false is going to be false. Therefore each time you set one of those binary variables to 0, you make the entire expression false.
Change the general form
binary_variable * logical_expression
into
(~binary_variable | logical_expression)
  3 commentaires
Walter Roberson
Walter Roberson le 10 Sep 2019
c = 0
true & c * (5==4) & true
ans = false
so setting c to 0 did not turn off the 5==4 test -- if it had somehow turned it off then the true & true on both sides should lead to an overall true result.
However,
>> c = 0; true & (~c | (5==4)) & true
ans =
logical
1
Here the 5==4 test has been turned off, leaving the true & true to come out true.
>> c = 1; true & (~c | (5==4)) & true
ans =
logical
0
Here the 5==4 test has been turned on, leading to true & false & true which is overall false.
Jasraj Soni
Jasraj Soni le 10 Sep 2019
It works!!
Thank you so much Walter for your time.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Equivalent Baseband Simulation dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by