2016-10-14 14 views
0

MatrixE1의 각 열에 대한 막대 그래프를 그려야합니다. 어떻게이 일을 할 수 있습니까? 이것은 내가 지금까지 쓴 것입니다. 어떤 도움이라도 대단히 감사합니다.행렬의 열 히스토그램을 그리는 방법은 무엇입니까?

% Create a random 5 x 3 matrix filled with random values between 0 and 10 
a0 = 0; 
b0 = 10; 
r = a0 + (b0-a0).*rand(1,1); 
matrixA = [randi([0 10]) randi([0 10]) randi([0 10]); randi([0 10]) randi([0 10]) randi([0 10]); randi([0 10]) randi([0 10]) randi([0 10]); randi([0 10])  randi([0 10]) randi([0 10]); randi([0 10]) randi([0 10]) randi([0 10])] 
% Create identity matrix 3 x 3 
matrixB = eye(3,3) 

% Create new submatrix of A with the last 3 rows 
matrixC = matrixA(end-2 : end, :) 

% Pair wise multiplication of C and B 
matrixD = times(matrixC, matrixB) 

% Concatenate Matrix A and D 
matrixE1 = [matrixA ; matrixD] 

% Plot histogram of columns. 
matrixColumn1 = matrixE1(1 : end , end-2: end-2); 
matrixFColumn2 = matrixE1(1 : end, end -1 : end-1); 
matrixFColumn3 = matrixE1(1 : end, end : end); 
+0

'hist()'를 시도 했습니까? – Jeon

+0

무엇을 할 수 있습니까? hist (??). matrixE1의 모든 열에 대해 하나의 막대 그래프를 얻으려면 어떻게해야합니까? hist (matrixE1)를 수행해야합니까? –

답변

2

당신은 다음과 같이 matrixE1에 coloumns의 각 액세스 할 수 있습니다

firstCol = matrixE1(:,1); 
secondCol = matrixE1(:,2); 
thirdCol = matrixE1(:,3); 

을 ... 그리고 당신은 단순히 히스토그램을 음모 '명령 HIST()를 사용할 수 있습니다 . 내가 두 번째 질문을 이해한다면

hist(firstCol); 

그리고 : ''나는 무엇을 할 것이다 당신은 matrixE1 먼저 coloumn의 히스토그램을 그릴까요? hist (??). matrixE1의 모든 열에 대해 하나의 막대 그래프를 얻으려면 어떻게해야합니까? 히스토그램 (matrixE1)을 수행해야합니까? '' 한 coloumn의 히스토그램을 플로팅 한 후 명령 보류를 간단하게 사용할 수 있습니다. 그런 다음 동일한 플롯에 다른 막대 그래프를 그립니다. 예를 들어 matrixE1의 첫 번째와 두 번째 coloumn의 히스토그램을 동일한 플롯으로 플롯하려는 경우 다음과 같이 입력하십시오.

1
>> v1=randn(1000,1); % zero mean, unity stdev 
>> v2=randn(1000,1)+1; % mean at one, unity stdev 
>> V=[v1 v2]; % 1000 x 2 matrix 
>> hist(V,100); % 100 bins 
>> legend('v1', 'v2'); 

enter image description here

관련 문제