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

1 vue (au cours des 30 derniers jours)
menachom
menachom le 18 Avr 2019
Commenté : menachom le 19 Avr 2019
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 commentaires
Walter Roberson
Walter Roberson le 18 Avr 2019
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 le 19 Avr 2019
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)

Connectez-vous pour commenter.

Réponses (0)

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by