필터 지우기
필터 지우기

How to filter a datasheet?

조회 수: 2 (최근 30일)
Jasraj Soni
Jasraj Soni 2019년 9월 10일
댓글: Jasraj Soni 2019년 9월 10일
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.

채택된 답변

Walter Roberson
Walter Roberson 2019년 9월 10일
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
Walter Roberson
Walter Roberson 2019년 9월 10일
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 2019년 9월 10일
It works!!
Thank you so much Walter for your time.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Equivalent Baseband Simulation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by