bigger/smaller or equal to for integers not working when numbers are close
조회 수: 2 (최근 30일)
이전 댓글 표시
I am trying to find integers in a matrix that are within x-percentiles. I am converting the values in my matrix to integers by multiplying and rounding to avoid round errors coming from using floating point numbers. I have used the num2strexact function to confirm that the numbers in my matrix are exact and not approximations. The code is below. In this example, I have set the percentiles to 0 and 100, meaning I should be getting all numbers to meet the conditions I have set. However, when the numbers are close to the percentile values I have set, I am getting some zeroes (as if the conditions were not met). Am I misunderstanding something as how Matlab works (Im new to this). I appreciate any help
PC=round(1000*rand(50,30));
E=round(prctile(PC,0,1));
F=round(prctile(PC,100,1));
ConditionsResults=zeros(50,30,65);
for n=1:65
for pc=1:30
for i=1:50
if (PC(i,pc)-E)>=0 & (F-PC(i,pc))>=0
ConditionsResults(i,pc,n)=1;
else
ConditionsResults(i,pc,n)=0;
end;
end
end
end
댓글 수: 6
Walter Roberson
2019년 4월 18일
That code could be vectorized ;-)
Question: why are you repeating it 65 times when you do not use n as part of the calculations?
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!