이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
If I run the code "rand(4,4)" then that will give me a 4x4 matrix with random numbers between 0 and 1. How do I then get Matlab to group these data into groups like 0 - 0.09, 0.1 - 0.19, 0.2, 0.29, etc, which I can then plot in a histogram.
채택된 답변
Image Analyst
2012년 11월 7일
2 개 추천
Try this demo. Just copy, paste, and run:
clc; % Clear the command window.
clearvars; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
format longg;
format compact;
fontSize = 20;
data = rand(40,40)
% take hist of data. Use (:) to convert it to a 1D vector.
binWidth = 0.1;
binEdges = 0.0 : binWidth : 1.0;
[counts values] = histc(data(:), binEdges);
bar(binEdges+ binWidth/2, counts, 'BarWidth', 1, 'FaceColor', [.4 .1 .7]);
grid on;
title('Histogram of Data', 'FontSize', fontSize);
xlabel('Bin Value', 'FontSize', fontSize);
ylabel('Counts in the bin', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);
댓글 수: 7
Dipesh
2012년 11월 7일
Well that gives me a graph and everything but it doesn't help much in my case. I still don't know how to get that to group my data together.
Have you actually read the documentation? histc does exactly what you ask for:
[n,bin] = histc(...) also returns an index matrix bin. If x is a vector, n(k) = sum(bin==k). bin is zero for out of range values. If x is an M-by-N matrix, then
for j=1:N,
n(k,j) = sum(bin(:,j)==k);
end
You just need to make your matrix a column vector if you want the linear indexes.
Image Analyst
2012년 11월 7일
Well then describe what you mean by "group" because everyone here is thinking histogram. A histogram is a count of how many of your original data points fall into a range of values, which we consider the "group". Obviously you have a different definition of group than everyone else.
Dipesh
2012년 11월 7일
I've been reading histc but I don't understand 100%. By group data, what I mean is this:
If I have 4 random numbers: 0.1256, 0.0365, 0.6365 and 0.0896
Then, I want to group them and counts how many are in each group. I.e within the interval 0 - 0.0999 we have 2 numbers, within 0.1 - 0.1999 we have 1 number, etc.
Image Analyst
2012년 11월 7일
That's exactly what histc does. Try my demo and see. Change 40 to 4 or so to get a smaller number to manually verify with.
Ok, I kindof get how histc works now, but I can't seem to get it to work for my data. I keep typing in
Y = rand(4)
Y =
0.2785 0.1576 0.8003 0.7922
0.5469 0.9706 0.1419 0.9595
0.9575 0.9572 0.4218 0.6557
0.9649 0.4854 0.9157 0.0357
histc(Y, 0.1:0.1:0.1999)
ans =
0 0 0 0
Why do I keep getting 4 zeros? Should it not go: (0 1 1 0)? Because there is 1 number between 0.1 and 0.1999 in columns 2 and 3, and 0 in the rest.
If I change the bit inside the histc command to (Y, 0.1:0.001:0.1999), it gives me a huge matrix with a couple of 1's in in, but it doesn't count the number of ones, so if I let that histc command be some letter A, I get numel(A) = row * columns of the matrix.
EDIT: I figured out that big matrix thing is actually the right way, and then I just use "sum" to get the total number and then I can plot these total numbers against the intervals?
Dipesh
2012년 11월 7일
Think I've got it now.
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
참고 항목
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)
