필터 지우기
필터 지우기

Newbie: how to apply some condition loop

조회 수: 1 (최근 30일)
Usman  Ali
Usman Ali 2012년 9월 20일
I have to take product of 2 vectors, find the min: in output vector and delete that element, I will try to simply my Question with an example,
1st case: lets given a vector v= [363 363 147 147 147 147 588]; with probabilites p_1 = [0.1 0.1 0.3 0.1 0.1 0.2 0.1];
their product z = v.*p_1 = [36.3 36.3 44.1 14.7 14.7 29.4 58.8];
I used, min_z=find(z==min(z)) that shows In 'z' 14.7 is the min. at index 4&5. One of them has to be deleted, either 4th column or 5th comlumn. changes shall also be made in p, here the probability distribution rule is, p(kept) = p(kept)+p(removed). this 'to b kept and to b deleted' are decided on the basis of min: value's indeces in output 'z'.
In above case min from 'z' are at 4th and 5th column, let say if 5th is deleted and 4th is kept, it is then p(4)=p(4)+p(5) = 0.1+0.1= 0.2 at 4th column, i.e. p_2 = [0.1 0.1 0.3 0.2 0.2 0.1]
In above case where 'z' give 2 indeces for a min: value this 'find' comand works fine, what if we have 2nd case.
2nd case: let v = [363 363 147 2187 147 588] and p_2 =[0.1 0.1 0.3 0.2 0.2 0.1]
this time z= v.*p_2 = [36.3 36.3 44.1 437.4 29.4 58.8] and the 'find' comand gives me only 1 min: i.e. 29.4 at 5th column, i can delete this 5th column but its duplicate does not exist in ouput 'z', so for making changes in 'p' this time i have to look for min. values in input 'v' and here i used min_v = find(v==min(v));
so I manualy use min_z = find(z==min(z)) for 1st case and min_v = find(v==min(v)) for 2nd case
Question: I am not good in understanding loops, so Is there any possible way that i Use these 2 formula's to be in a conditional loop that e.g in genearl use min_z but for special conditions where it gives less then 2 indeces then use min_v..
  댓글 수: 1
Jan
Jan 2012년 9월 20일
Ok. What is your question? It seems like you have a strategy already, so just implement it.

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

답변 (1개)

Image Analyst
Image Analyst 2012년 9월 20일
Seems like a weird thing to do. How should we know if you want to add the value that is to be deleted to the duplicate min value in vector p (like the first case), or if you want to add it to some other place that you didn't specify (like in the second case).
Even in the first case, once you've done the addition (added p(4) to p(5)), where does that addition go? Do you assign it anywhere?
Same for the second case. You add p(5) to some value (perhaps the min???) of v, but again, where does it go? Does it go back into p, or does it go into z, or does it go into some other, new variable? Please state your needs more clearly.
  댓글 수: 1
Usman  Ali
Usman Ali 2012년 9월 20일
sorry i missed a point there yes it goes back to p, compare p in both cases above,
p_1 = [0.1 0.1 0.3 0.1 0.1 0.2 0.1];
p_2 = [0.1 0.1 0.3 0.2 0.2 0.1]
Actually probability distribution rule is like, p(kept) = p(kept)+p(removed). this 'to b kept and to b deleted' are decided on the basis of being the min: value's indeces in output 'z'.
In above case min are at 4th and 5th column, let say if 5th is deleted and 4th is kept, it is then p(4)=p(4)+p(5),
In case 'z' give 2 indeces for a min: value then it's fine, but if not then i have to look into 'v'
so I can use min_z = find(z==min(z)) and min_v = find(v==min(v)) i want these 2 formula's to be in a conditional loop that e.g in genearl use min_z but it gives less then 2 indeces then use min_v..

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

카테고리

Help CenterFile Exchange에서 COM Component Integration에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by