bigger/smaller or equal to for integers not working when numbers are close

조회 수: 2 (최근 30일)
menachom
menachom 2019년 4월 18일
댓글: menachom 2019년 4월 19일
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
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?
menachom
menachom 2019년 4월 19일
Thanks for the input!
The additional loop (65 times) makes sense in the context of the rest of the code (the value of n is used to determine which cutoffs are used)

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

답변 (0개)

카테고리

Help CenterFile Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by