problem in using if command
이전 댓글 표시
hello everyone,
i have 25 observed values. Now i am generating new 25 values with a formula. Now what I want is that the generated value should b near to any of the observed 25 values.
for example: observed value O= 1 2 3 4 5 6 7 8 9
now I am generating the value using formula: 1+i. So i am writing a code like
for j=1:25
for i=1:50
v(j)=1+i
if(v(j)-O=1)
break
end
end
end
So my question is that I want that the generated value v(1) should have a maximum difference of 1 with any of the observed data O. And when we generate v(2) then again it should have max difference of 1 with observed O but it should not consider that observed value which it has considered during v(1). Means if for v(1) is calculated with difference with O(3), then for v(2) when "if" command executes than it should not consider O(3) again.
댓글 수: 3
Walter Roberson
2019년 7월 25일
This can require some backtracking. There are three possible acceptable matches to any given element of O: an exact match, or an exact match minus 1, or an exact match plus 1. For example if 5 6 8 is in O and we generate 7 then we could match it against the 6 or the 8. But when we do either, we remove that element from being available for future matches, and that could matter because it might be the only value that could be matched against a different element.
The problem becomes easier if some guarantees can be made as to how v elements are to be generated. With your current code your trial values are 1:50. Does that hold for your actual code?
Can O have duplicate values?
Prakhar Modi
2019년 7월 25일
Walter Roberson
2019년 7월 25일
https://www.geeksforgeeks.org/maximum-bipartite-matching/
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Random Number Generation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!