How to filter a datasheet?

3 visualizaciones (últimos 30 días)
Jasraj Soni
Jasraj Soni el 10 de Sept. de 2019
Comentada: Jasraj Soni el 10 de Sept. de 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.

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Sept. de 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 comentarios
Walter Roberson
Walter Roberson el 10 de Sept. de 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 el 10 de Sept. de 2019
It works!!
Thank you so much Walter for your time.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Equivalent Baseband Simulation en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by