How to render a sparse matrix in MATLAB?

So I have this matrix here and it is 13 x 8198 in size. (I named it "blah").

It is a sparse matrix where most of its entries are 0. When I do imagesc (blah) I get the following image:

enter image description here

Clearly this is useless because I cannot clearly see the non-null elements. I have tried playing around with color scaling to no avail.

Anyway, I was wondering if there might be a better way to render this matrix in MATLAB? I am developing an algorithm and would like to see some things inside a matrix.

Thank!

+3


source to share


1 answer


Try it spy

; it is designed to do just that.

The problem is what spy

makes the axes equal and your data is 13 x 8198, so the first axis is almost invisible compared to the second. daspect

can fix it.

>> spy(blah)
>> daspect([400 1 1])

      

V93lK9b.png




spy

does not have the ability to draw differently by signs. One option is to edit the source to add this capability (it's implemented in Matlab and you can get the source by running edit spy

). However, it's easier to hack only the individual positive and negative parts:

>> daspect([400 1 1]);
>> hold on;
>> spy(max(blah, 0), 'b');
>> spy(min(blah, 0), 'r');

      

tXYXYtf.png

This leads to the unfortunate side effect of creating places where the close together positive and negative sides have a dominant influence on the second one plotted here by the negatives (for example, in the top rows of your matrix). I'm not sure what to do with this, other than maybe fiddling with marker sizes. You could of course do it in both orders and compare.

+7


source







All Articles