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 件のコメント

jonas
jonas 2018 年 10 月 23 日
編集済み: jonas 2018 年 10 月 23 日
And what is the problem with
plot(YourMatrix)
?
Feliciano Döring
Feliciano Döring 2018 年 10 月 23 日
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.
KSSV
KSSV 2018 年 10 月 24 日
How about waterfall?
Feliciano Döring
Feliciano Döring 2018 年 10 月 24 日
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 2018 年 10 月 24 日
編集済み: jonas 2018 年 10 月 24 日
imshow? pcolor? Imagesc? Scatter?
I still do not understand what you want to do.
Feliciano Döring
Feliciano Döring 2018 年 10 月 24 日
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 2018 年 10 月 24 日
編集済み: jonas 2018 年 10 月 24 日
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?
Feliciano Döring
Feliciano Döring 2018 年 10 月 24 日
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 2018 年 10 月 24 日
編集済み: jonas 2018 年 10 月 24 日
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?
Feliciano Döring
Feliciano Döring 2018 年 10 月 24 日
Yes, of course, here it is. Less of a squetch more of a print of a book
jonas
jonas 2018 年 10 月 24 日
編集済み: jonas 2018 年 10 月 24 日
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)
Feliciano Döring
Feliciano Döring 2018 年 10 月 24 日
The plot doesn't quite fit. But here take a look
Feliciano Döring
Feliciano Döring 2018 年 10 月 24 日
Yes, something like this

サインインしてコメントする。

 採用された回答

jonas
jonas 2018 年 10 月 24 日
編集済み: jonas 2018 年 10 月 24 日

0 投票

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 件のコメント

Feliciano Döring
Feliciano Döring 2018 年 10 月 24 日
Thanks, this helps a lot! And double thanks for the patience :D
jonas
jonas 2018 年 10 月 24 日
My pleasure! It's true that a picture says more than a thousand words ;)
Feliciano Döring
Feliciano Döring 2018 年 10 月 29 日
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.
jonas
jonas 2018 年 10 月 29 日
I believe I adressed this in the original answer?
y = A(j,:)./scale+(size(A,1)-j);
Feliciano Döring
Feliciano Döring 2018 年 10 月 29 日
Sorry, didn't pay attention '-.-

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeResizing and Reshaping Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by