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!