Picking up the correct index values

I have 4 arrays, two combinations of Nwell and Pwell voltages of Transistor 1 and Transistor 2
For transistor 1
vnw_1 =
0.00000 0.90000
vpw_1 =
-1.8000 -1.2000
So we define as (Vn, Vp) as (0.00000, -1.8000) and another (0.90000, -1.2000) these are the combination respectively.
for transistor 2
vnw_2 =
0.90000 0.00000
vpw_2 =
-1.20000 0.20000
Similarly we have (Vn, Vp) as (0.90000, -1.2000) and another (0.00000, 0.20000)
we can see that (0.90000, -1.2000) is common in T1 and T2.
I want to get the common voltage as the output
Answer (0.90000, -1.2000)
How do i do that? There is nothing linked to the concepts of transistors, just i need that combination as the output. How do i do that? Please help me

 Accepted Answer

You should probably rethink the way you store these values, because this is much more difficult to index than it needs to be.
vnw_1 = [ 0.00000 0.90000];
vpw_1 = [-1.80000 -1.20000];
vnw_2 = [ 0.90000 0.00000];
vpw_2 = [-1.20000 0.20000];
Answer=[];
for T1_ind=1:2
T1=[vnw_1(T1_ind) vpw_1(T1_ind)];
for T2_ind=1:2
T2=[vnw_2(T2_ind) vpw_2(T2_ind)];
if isequal(T1,T2)
Answer=T1;
end
end
end

9 Comments

Ganesh Kini
Ganesh Kini on 27 May 2020
Edited: Ganesh Kini on 27 May 2020
Hi
If there are more than 2 values, say suppose its n.
How do i define the value of n
I tried it didnt give me the answer,
Output
>> Answer
Answer = [ ](0x0)
Then you ran different code, or you used different data. You might need to use ismembertol instead of isequal.
Also, if you want more than two values, you should creat vnw and vpw arrays, not numbered variables. It is possible to generate T3 from vnw_3 and vpw_3 etc, but you shouldn't.
Ganesh Kini
Ganesh Kini on 27 May 2020
Edited: Ganesh Kini on 27 May 2020
No i didnt,
I used ismember function and i got the following
Answer =
0 0.9000 2.0000 -1.8000 -1.2000 2.0000
Could you please help me out. i have tried several ways, but no result
We could argue back and forth, but you have a value of 2 in that array, which wasn't anywhere in what you posted previously. What exact code are you using and what is your exact data?
Also, I suggested using ismembertol, not ismember, but we will cross that bridge when we get there.
It appears that someone already arrived at that bridge, still not using ismembertol:
Hi,
Thanks for all the suggestions, It works, But what if it has different dimensions ?
VNW1
-0.20000 -0.20000
vpw1 =
-0.90000 -1.80000
VNW2 =
1.20000 0.30000 0.90000 -0.20000 1.20000
VPW2=
0.00000 -1.20000 -0.90000 -1.80000 -0.30000
Could you please help ?
First convert your four vectors to two arrays so you can compare them. Make sure the things you want to compare are on the rows of your array. Then you can use ismembertol. You could also try with ismember first, but if your decimal values can't be expressed as a binary fraction you may get rounding errors. (just like you can't store 1/3 in a decimal value, Matlab can't store every value without rounding)
VNW1=[-0.20000 -0.20000];
vpw1=[-0.90000 -1.80000];
VNW2=[1.20000 0.30000 0.90000 -0.20000 1.20000];
VPW2=[0.00000 -1.20000 -0.90000 -1.80000 -0.30000];
T1=[VNW1(:) vpw1(:)];
T2=[VNW2(:) VPW2(:)];
L=ismembertol(T1,T2,'rows');
matches=T1(L,:);
Thanks for the help it works fine

Sign in to comment.

More Answers (0)

Asked:

on 27 May 2020

Commented:

on 28 May 2020

Community Treasure Hunt

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

Start Hunting!