How do plot rows of your matrix into a histogram?

11 次查看(过去 30 天)
So usually hist allows you to plot the columns of your matrix into a histogram. i wish to plot the rows. Below is my matrix.
my first column is my ordinal information (so its not counted in the histogram). I also wish to plot for every 2 rows. Is that possible??
0 0.0032 0.0032 0.0032
1.0000 0.0010 0.0028 0.0016
2.0000 0.0012 0.0001 0.0013
3.0000 0.0000 0.0009 0.0025
4.0000 0.0006 0.0000 0.0012
5.0000 0.0006 0.0021 0.0002
6.0000 0.0003 0.0000 0.0003
7.0000 0.0019 0.0016 0.0001

回答(1 个)

Image Analyst
Image Analyst 2021-11-25
Not sure what you mean by histogram. Is that your data or some kind of histogram of the data?
Anyway, to plot the rows of your matrix, row-by-row, you can do this:
m=[
0 0.0032 0.0032 0.0032
1.0000 0.0010 0.0028 0.0016
2.0000 0.0012 0.0001 0.0013
3.0000 0.0000 0.0009 0.0025
4.0000 0.0006 0.0000 0.0012
5.0000 0.0006 0.0021 0.0002
6.0000 0.0003 0.0000 0.0003
7.0000 0.0019 0.0016 0.0001];
[rows, columns] = size(m)
rows = 8
columns = 4
for row = 1 : rows
plot(m(row, 2:end), '.-', 'LineWidth', 3, 'MarkerSize', 40)
hold on;
legendStrings{row} = num2str(row);
end
legend(legendStrings)
grid on;
fontSize = 15;
title('m', 'FontSize', fontSize)
xlabel('x', 'FontSize',fontSize)
ylabel('y', 'FontSize',fontSize)

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by