How to group data in two column matrix
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
Hello, I have a set of data that I would like to analyse. The data is split into two columns in a matrix. Here is a cutout:
16,7115184526445 1,99856679248824
16,7765766713840 1,90380826928436
16,8203225632002 1,90759997561475
16,9296872927408 1,93705728785794
17,0247496340434 1,95221030451463
17,0840560047515 1,97156344341112
17,1728721040053 2,02042344983047
17,2760126971073 2,04365662563518
17,3427845325050 1,99056685824960
17,3555146973138 1,96334283757260
17,3614789932988 1,92935199439745
17,3759202152813 1,94379321637992
17,4269340102000 1,91489959400124
17,4440061891234 9,29514481185319
17,5122505102985 1,76049098118472
17,5544684974967 1,96252475665197
17,5760555781573 1,94415765182676
17,6300232798089 1,95817212166681
17,6986099837662 1,66717115625156
17,7054927064216 1,99368640911937
17,7158167904047 1,92410307580507
17,7416270003624 1,94991328576274
17,8656023527728 1,99398026720148
Now I want to group the left data into 10 classes like 10,20,30,40 etc... and calculate the mean values of the right data for each group. In a next step I want to plot the data with a bar for each group. I have sort the matrix according to the left column with sortrows. How can i go on?
Thanks for your help!
채택된 답변
Matt J
2018년 5월 16일
0 개 추천
Use splitapply() for the groupwise mean and bar() to generate the bar plot.
댓글 수: 14
leonidas86
2018년 5월 16일
Im running Matlab 2012b and can't use the function splitapply...
In that case, you can emulate it using accumarray().
[~,~,subs]=unique(groupIDs);
groupMeans = accumarray(subs,rightcolumn,[],@mean);
leonidas86
2018년 5월 16일
At the unique line I get the error that the subscript indices must either be real positive integers or logicals.
Then you have redefined "unique" as a variable. Check this by:
which unique -all
The solution is the use a different name for your variable.
leonidas86
2018년 5월 16일
No I dont use unique as a variable name.
Matt J
2018년 5월 16일
We would need to see code and error messages.
leonidas86
2018년 5월 17일
Subscript indices must either be real positive integers or logicals.
Error in histogram_test (line 71) [~,~,subs]=unique(complete(pPos));
pPos includes the left column of the matrix above.
Matt J
2018년 5월 17일
Since pPos are not integers, they cannot be used as indices to the array 'complete'.
leonidas86
2018년 5월 17일
How i can I convert pPos to integers? Can I use "floor"?
Jan
2018년 5월 17일
It depends on what you need. If floor is matching, use floor.
Thanks for your help. Now it works.
pPosr=round(pPos);
[~,~,subs]=unique(pPosr);
groupMeans = accumarray(subs,pDiff,[],@mean);
The unique function actually creates 59 groups. Is it possible to create n groups?
You could also use histc, e.g.,
[~,groupID]=histc(pPos,0:10:100);
leonidas86
2018년 5월 17일
편집: leonidas86
2018년 5월 17일
I have one last question about plotting the histogram.
groupPosMeans = accumarray(groupID,pPos,[],@mean);
Above I calculated my x axis values. Then plotting with:
bar(groupPosMeans,groupDiffMeans);
How can I set the right x axis scale according to groupPosMeans?
I made it:
xTick=round(groupPosMeans);
set(gca, 'XTick', xTick);
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Box Plots에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
