умножить гистограмму в матрице - PullRequest
9 голосов
/ 24 июня 2011

Я бы хотел создать сюжет, подобный следующему, в Matlab.

enter image description here

Или может быть что-то вроде этого enter image description here

Ответы [ 2 ]

15 голосов
/ 24 июня 2011

Вы можете использовать bar (...) или Hist (...), чтобы получить желаемые результаты. Рассмотрим следующий код с результатами, показанными ниже:

% Make some play data:
x = randn(100,3);
[y, b] = hist(x);

% You can plot on your own bar chart:
figure(82);
bar(b,y, 'grouped');
title('Grouped bar chart');

% Bust histogram will work here:
figure(44);
hist(x);
title('Histogram Automatically Grouping');

% Consider stack for the other type:
figure(83);
bar(b,y,'stacked');
title('Stacked bar chart');

Group Bar Result Histogram Results Stacked Bar Result

Если ваши данные имеют разные размеры, и вы хотите делать гистограммы, вы можете сами выбрать бины, чтобы принудительно заставить результаты исторических (...) иметь одинаковый размер, затем построить результаты в виде матрицы, как в:

data1 = randn(100,1);       % data of one size
data2 = randn(25, 1);       % data of another size!

myBins = linspace(-3,3,10); % pick my own bin locations

% Hists will be the same size because we set the bin locations:
y1 = hist(data1, myBins);   
y2 = hist(data2, myBins);

% plot the results:
figure(3);
bar(myBins, [y1;y2]');
title('Mixed size result');

Со следующими результатами:

enter image description here

1 голос
/ 24 июня 2011

Разве hist уже не делает первый?

С help hist:

N = HIST(Y) bins the elements of Y into 10 equally spaced containers
and returns the number of elements in each container.  If Y is a
matrix, HIST works down the columns.

Для второго взгляда на help bar

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...