Filtering through multiple vectors for a single set of values

조회 수: 1 (최근 30일)
Chad Williams
Chad Williams 2020년 2월 26일
댓글: Chad Williams 2020년 2월 26일
I get the roots below using an equation solver & filtering out "unrealistic" roots with conditional/logical statements.
The part I'm stuck on is on how to code this proccess:
1) Identify the common integer at the beginning of the vector sets between Q1 - Q6 (in this case, 3)
2) Filter out the other vector sets (2,4)
3) Pull out the long decimal number from the #3 vector sets & assign that as the new Q1 Q2 etc
Q1 =
[ 2, 1, 1, 0.058437210716851634542028894189494]
[ 3, 1, 1, 0.058688566689220710419984397081727]
Q2 =
[ 2, 1, 1, 0.0098069127074167821263054682858129]
[ 3, 1, 1, 0.0078508603596354954926620927235173]
Q3 =
[ 2, 1, 1, 0.0015627892831483654579711058105059]
[ 3, 1, 1, 0.0013114333107792895800156029182727]
Q4 =
[ 2, 1, 1, 0.041562789283148365457971105810506]
[ 3, 1, 1, 0.041311433310779289580015602918273]
Q5 =
[ 3, 1, 1, 0.00083770632958521492732230435821]
[ 4, 1, 1, 0.020473081482478049769416844651268]
Q6 =
[ 3, 1, 1, 0.01083770632958521492732230435821]
[ 4, 1, 1, 0.030473081482478049769416844651268]
  댓글 수: 2
Jacob Wood
Jacob Wood 2020년 2월 26일
Will there always be a single integer that appears once in every Q_i?
Chad Williams
Chad Williams 2020년 2월 26일
Yes it's purposely put there so the vector can be identified & only exists to point to the root. It will always be 1,2,3 & 4 for this application.
Below is the orginal output where you can see what would be 1 & 4 being filtered out as they are negative.
I just get stuck on trying to translate into code.
Q1 =
-0.15604402697446315680842658977416
0.058437210716851634542028894189494
0.058688566689220710419984397081727
-0.05986135947318542852737264354485
Q1 =
[ 2, 0.058437210716851634542028894189494]
[ 3, 0.058688566689220710419984397081727]

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

답변 (2개)

KSSV
KSSV 2020년 2월 26일
1) Identify the common integer at the beginning of the vector sets between Q1 - Q6 (in this case, 3)
Read about unique for this.
2) Filter out the other vector sets (2,4)
Use ismember for this.
3) Pull out the long decimal number from the #3 vector sets & assign that as the new Q1 Q2 etc
You can use logical indexing for this.

Jacob Wood
Jacob Wood 2020년 2월 26일
편집: Jacob Wood 2020년 2월 26일
Chad,
This might be a solution for you. It picks the most common root label and grabs all of them:
Q1 = [ 2, 1, 1, 0.058437210716851634542028894189494;
3, 1, 1, 0.058688566689220710419984397081727];
Q2 = [ 2, 1, 1, 0.0098069127074167821263054682858129;
3, 1, 1, 0.0078508603596354954926620927235173];
Q3 = [ 2, 1, 1, 0.0015627892831483654579711058105059;
3, 1, 1, 0.0013114333107792895800156029182727];
Q4 = [ 2, 1, 1, 0.041562789283148365457971105810506;
3, 1, 1, 0.041311433310779289580015602918273];
Q5 = [ 3, 1, 1, 0.00083770632958521492732230435821;
4, 1, 1, 0.020473081482478049769416844651268];
Q6 = [ 3, 1, 1, 0.01083770632958521492732230435821;
4, 1, 1, 0.030473081482478049769416844651268];
Q = [Q1;Q2;Q3;Q4;Q5;Q6];
select_int = mode(Q(:,1));
roots = Q(Q(:,1)==select_int,4);
  댓글 수: 3
Jacob Wood
Jacob Wood 2020년 2월 26일
I'm not sure I'm following. What is happening in these lines? Is this output from running the code?
[ 2, 0.058437210716851634542028894189494]
[ 3, 0.058688566689220710419984397081727]
Chad Williams
Chad Williams 2020년 2월 26일
Yes those are the outputs.

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

카테고리

Help CenterFile Exchange에서 Signal Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by