How would i display a matrix as a graph?

I have a matrix in which the values are mainly in the main diagonal. What i want to do is create a bigger matrix in which each row of the matrix is a line so it would show the values of each row across several lines. So for example if i have an identity 3x3 matrix, it would be three lines with spikes on the main diagonal.

13 Comments

And what is the problem with
plot(YourMatrix)
?
It doesn't display it as i want it to. Plot(matrix) will only show me a single line with the variations of the values i have.
How about waterfall?
I tried the waterfall plot and it gets close to how i want to display it, but i was looking for something more like 2D, not 3D.
jonas
jonas on 24 Oct 2018
Edited: jonas on 24 Oct 2018
imshow? pcolor? Imagesc? Scatter?
I still do not understand what you want to do.
Honestly i think imshow is almost the same as imagesc and i tried both hahaha. Tried pcolor and it wasn't that much different from the previous and scatter didn't quite work for the matrix
jonas
jonas on 24 Oct 2018
Edited: jonas on 24 Oct 2018
pcolor and/or imagesc omits one row/column on the edge, so if you have a 3x3 matrix you will get 2x2 squares. This is not a problem with imshow. The problem with imshow is that you need regular spacing between pixels. Anyway, is this type of grid what you were going for?
Oh, i didn't know thanks! But it's not what i'm looking for. I used the identity matrix as an example but what my actual matrix has main values on the main diagonal with decreasing values on each side of the rows, so each row would look more like a gaussian distribution.
jonas
jonas on 24 Oct 2018
Edited: jonas on 24 Oct 2018
Maybe it's clear to you how you want to visualize your data, maybe not, maybe you only have a vague picture in your head. Regardless, what you just said does not describe how you want to visualize your data. The nature of your data does not describe how you want to visualize your data. In fact, the nature of your data does not matter at all. All that matters is how you want to visualize the data in question. Can you... draw a sketch by hand?
Yes, of course, here it is. Less of a squetch more of a print of a book
jonas
jonas on 24 Oct 2018
Edited: jonas on 24 Oct 2018
Back to my original enquiry, what is wrong with plot? Does the rows of your matrix describe the coordinates of these distribution plots? Can you upload your data?
In the case of the identity matrix, are you looking for something like this? (5x5)
The plot doesn't quite fit. But here take a look
Yes, something like this

Sign in to comment.

 Accepted Answer

jonas
jonas on 24 Oct 2018
Edited: jonas on 24 Oct 2018
Here's a custom plot type I made. It may look upside down, but the value on the y-axis denotes the row number. The "peak value" of the lines are scaled and only show relative height.
A = eye(5);
scale = 2;
figure;hold on
for j = 1:size(A,1);
y = A(j,:)./scale+j;
fill([1 1:size(A,1) size(A,1)],[min(y) y min(y)],'r');
end
If you prefer the reverse order, as they appear in the matrix, then just change the 5th line to
y = A(j,:)./scale+(size(A,1)-j);

5 Comments

Thanks, this helps a lot! And double thanks for the patience :D
My pleasure! It's true that a picture says more than a thousand words ;)
One last question, I've been wondering if there is a way to change the matrix so that the diagonal goes from top left to down right.
I believe I adressed this in the original answer?
y = A(j,:)./scale+(size(A,1)-j);
Sorry, didn't pay attention '-.-

Sign in to comment.

More Answers (0)

Categories

Find more on Mathematics in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!