How to visualize a sparse matrix in MATLAB?

扶醉桌前 提交于 2019-12-06 01:59:00

Try spy; it's intended for exactly that.

The problem is that spy makes the axes equal, and your data is 13 x 8198, so the first axis is almost invisible compared to the second one. daspect can fix that.

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


spy doesn't have an option to plot differently by signs. One option would be to edit the source to add that capability (it's implemented in matlab, and you can get the source by running edit spy). An easier hack, though, is to just spy the positive and negative parts separately:

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

This has the unfortunate side effect of making places where positives and negatives are close together appear dominated by the second one plotted, here the negatives (e.g. in the top rows of your matrix). I'm not sure what to do about that other than maybe fiddling with marker sizes. You could of course do it in both orders and compare.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!