finding out the frequencies of numbers within coloumns

조회 수: 2 (최근 30일)
Yasmine
Yasmine 2012년 2월 28일
Hii I have two coloumns matrix, first coloumn temperatures, while the other moisture values.. I want to find out the frequeincies for each temperature with each moisture and vice versa, ensuring to take all the probabilities ofoverlapping. For example:what is the number of occurence of 1 degree and 0.23 moisture, 1 degree and 0.4 moisture, and so on then, 2 degree with each of moisturesvalues.. CAN YOU HELP ME PLZ

채택된 답변

Sven
Sven 2012년 2월 28일
Hi Yasmine. Let's first make some random temperatures and moistures:
tempmoist = randi(20,200,2);
Now let's find the unique pairs of these, and get a list matching all our temperatures/moistures to those unique pairs.
[unqVals, ~, grpNos] = unique(tempmoist,'rows')
Now let's use histogram to count the number of occurrences of each of those pairs.
counts = histc(grpNos, 1:max(grpNos))
You can display all the unique temperature/moisture pairs, along with the number of times they occur by joining them together like this:
[unqVals counts]
Hope that's the answer you were looking for.

추가 답변 (3개)

Yasmine
Yasmine 2012년 2월 28일
Hi seven thank you that was helpful when i have inunique pairs but what if i have unique ones and i want to put them in ranges coz i have in decimal places, so for example i want the number of unique pairs if the tempertures from 1 to 1.9 degrees and when moisture is from 0.04 to 0.08 and so on...
  댓글 수: 1
Sven
Sven 2012년 2월 29일
Then you just need to do one prior step: choose your "ranges", then round your values into those ranges. For example, the following lines make some random numbers between 0 and 1, then makes 11 bins from 0 to 1 at intervals of 0.1, then asks, "which bin is each of my values nearest to?". After getting this kind of result for your data, you can run the code in the answer.
rawData = rand(50,1)
binCenters = 0:0.1:1
whichBins = interp1(binCenters, 1:length(binCenters), rawData,'nearest')

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


Yasmine
Yasmine 2012년 3월 1일
the matrix i have is already of unique pairs of two coloumns, alp= Tem moist 1 0.77 2 0.08 2 0.78 2 0.90 3 0.09 3 0.1 4 0.13
and so on... now i want to know what is the occurence no. when temp==2 and moist is between (0.04 to 0.08)for example.. then when temp==2 and moist is between (0.09 to 0.12).. then when temp is 3 and with same ranges of moist.. I hope that is clear ..??

Yasmine
Yasmine 2012년 3월 1일
OOPs the numbers werent written in the right format: first coloumn of matrix is(temp) 1, 2,2,2,3,3,4 and second one (moist): 0.77,0.08,0.78,0.90,0.09,0.14,0.13

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by