probability of occurence of a specific value
이전 댓글 표시
Hi all! I have a question concerning the probability of occurence of a specific value. I have a set of precipitation data and would like to find the frequency histogram for precipitation values equal to zero. is there someone here who is able to solve this easy problem? :) thank you
답변 (3개)
Guillaume
2015년 3월 10일
You must have at least two bins for the histogram functions, you could just set the threshold of the second bin to something very small:
h = histc(data, [0 0.00001]);
But if you really just want the number of values equal to 0:
num0 = sum(data == 0);
%or num0 = sum(abs(data < 0.00001)) if you want to include values very close to 0
댓글 수: 5
Camilla Santicoli
2015년 3월 10일
Guillaume
2015년 3월 10일
I would do it like this:
precipitation = [0 0 0 0 0 0.2 0.3 1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 9.9 10.1 11.11 12.12]; %for example
filteredprecipitation = precipitation(precipitation == 0 | precipitation >= 1); %get rid of values >0 and <1
precipitationhistogram = histc(filteredprecipitation, [0 1 3 10 Inf]);
precipitationhistogram = precipitationhistogram(1:end-1)
Basically, remove the values > 0 and <= 1 so that the first bin [0 1[ only includes the 0 values. The second bin is the values in the range [1 3[, the third in the range [3 10[, the 4th in the range [10 Inf[ and the last, just the Inf values (so I get rid of that one).
Guillaume
2015년 3월 10일
I would like the first bar to be only with 0 values, the second one with values between 0.1 and 1 and the third one with values between 1 and 3...the rest is the same
You just have to change the filter and the bins:
filteredprecipitation = precipitation(precipitation == 0 | precipitation >= 0.1); %get rid of values >0 and <0.1
precipitationhistogram = histc(filteredprecipitation, [0 0.1 1 3 10 Inf]);
precipitationhistogram = precipitationhistogram(1:end-1)
Guillaume
2015년 3월 10일
moreover I would like to plot a relative frequency histogram instead of the normal one
I assume that's what you want:
precipitationhistogram = precipitationhistogram / sum(precipitationhistogram);
precipitationhistogram = histcounts(filteredprecipitation, [0 0.1 1 3 10 Inf], 'Normalization', 'probability');
Camilla Santicoli
2015년 3월 10일
Camilla Santicoli
2015년 3월 10일
0 개 추천
댓글 수: 5
Guillaume
2015년 3월 10일
Is this in response to my answer? If yes, please reply with Comment on this Answer as you did the first time rather than starting a new answer.
The reason I'm confused is that there's no plot in my answer.
bar(precipitationhistogram)
would be how I'd plot it, and that works fine with my example.
You said you wanted just the precipitation == 0 in your first bin and [1 3[ in the second bin. That's exactly what my code does.
Camilla Santicoli
2015년 3월 10일
Camilla Santicoli
2015년 3월 10일
Guillaume
2015년 3월 10일
I'm replying in a comment to my original answer
Camilla Santicoli
2015년 3월 10일
카테고리
도움말 센터 및 File Exchange에서 Box Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!