How do plot rows of your matrix into a histogram?

조회 수: 9(최근 30일)
Dameon Solestro
Dameon Solestro 2021년 11월 25일
답변: Image Analyst 2021년 11월 25일
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

답변(2개)

VBBV
VBBV 2021년 11월 25일
A= [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]
bar(A(1:2:end,2:end))
Try with bar function

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)

Community Treasure Hunt

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

Start Hunting!

Translated by