How do plot rows of your matrix into a histogram?
11 views (last 30 days)
Show older comments
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
0 Comments
Answers (1)
Image Analyst
on 25 Nov 2021
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)
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)
0 Comments
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!