bigger/smaller or equal to for integers not working when numbers are close
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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
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?
Réponses (0)
Voir également
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!