How do I Iterate over similar elements in an array
이전 댓글 표시
Hi, I have an input text file that looks like what's below (the actual text file is 1000 lines so I'm just providing a sample). Anyway, I need to compute the mean, and variance (to fit data into a Gaussian). The last column of input is "class" I need to compute the values for each unique class. So for each of the 10 classes I need the mean and variance. But the data is not ordered. The output should look like: Class %d Column %d Mean %.2f Variance %.2f. How can I accomplish this goal? Thanks a ton
0.5000 0.4600 0.6400 0.3600 0.5000 0 0.4900 0.2200 1
0.5300 0.5600 0.4900 0.4600 0.5000 0 0.5200 0.2200 1
0.5200 0.5300 0.5800 0.6900 0.5000 0 0.5000 0.2200 1
0.6700 0.6200 0.5400 0.4300 0.5000 0 0.5300 0.2200 1
0.4500 0.5700 0.3000 0.1700 0.5000 0 0.5100 0.2200 3
0.6800 0.5300 0.4400 0.3100 0.5000 0 0.5100 0.2200 1
0.3800 0.4200 0.3100 0.3500 0.5000 0 0.5200 0.2200 3
0.4800 0.4600 0.5800 0.2600 0.5000 0 0.4400 0.2200 2
댓글 수: 4
jonas
2018년 2월 28일
Just to clarify, you want one set of values per column and class?
Faisal Alnahhas
2018년 2월 28일
jonas
2018년 2월 28일
Okay, I would suggest using logical indexing to group classes. For example, if A is your matrix then the mean for class 1 would be:
mean(A(A(:,end)==1,:))
Faisal Alnahhas
2018년 3월 1일
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!