MATLAB Answers

Filtering through multiple vectors for a single set of values

조회 수: 2(최근 30일)
Chad Williams
Chad Williams 26 Feb 2020
댓글: Chad Williams 26 Feb 2020
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 26 Feb 2020
Will there always be a single integer that appears once in every Q_i?
Chad Williams
Chad Williams 26 Feb 2020
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]

로그인 to comment.

답변(2개)

KSSV
KSSV 26 Feb 2020
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.

  댓글 수: 0

로그인 to comment.


Jacob Wood
Jacob Wood 26 Feb 2020
편집: Jacob Wood 26 Feb 2020
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

Chad Williams
Chad Williams 26 Feb 2020
That code works perfectly, however there is a formatting issue with implementing it into my main line of code. The formatting of my Q sets is different I'm assuming either to my preceeding code or the fact that it's symbolic before the calculations.
idx1 = find(Q1 < 0.1 & Q1 > 0);
[i1] = ind2sub(size(Q1), idx1);
Q1 = [i1 Q1(idx1)] %this is where I assume the issue is
Q1 = %output
[ 2, 0.058437210716851634542028894189494]
[ 3, 0.058688566689220710419984397081727]
Jacob Wood
Jacob Wood 26 Feb 2020
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 26 Feb 2020
Yes those are the outputs.

로그인 to comment.

이 질문에 답변하려면 로그인을(를) 수행하십시오.


Translated by