如何在MATLAB中可视化稀疏矩阵? [英] How to visualize a sparse matrix in MATLAB?

查看:684
本文介绍了如何在MATLAB中可视化稀疏矩阵?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个矩阵此处,它的大小为13 x8198.(我称之为"blah").

So I have this matrix here, and it is of size 13 x 8198. (I have called it 'blah').

这是一个稀疏矩阵,因为它的大多数条目都是0.当我执行imagesc(blah)时,我得到以下图像:

This is a sparse matrix, in that, most of its entries are 0. When I do an imagesc(blah), I get the following image:

显然,这毫无用处,因为我无法清楚地看到非零元素.我尝试过颜色缩放,但无济于事.

Clearly this is worthless because I cannot clearly see the non-zero elements. I have tried playing around with the color scaling, but to no avail.

无论如何,我想知道是否可能有更好的方法以某种方式在MATLAB中可视化此矩阵?我正在设计一种算法,希望能够在矩阵中看到某些东西.

Anyway, I was wondering if there might be a nicer way to be able to visualize this matrix in MATLAB somehow? I am designing an algorithm and would like to be able to see certain things int teh matrix.

谢谢!

推荐答案

尝试 spy ;正是出于这个目的.

Try spy; it's intended for exactly that.

问题在于spy使轴相等,并且您的数据为13 x 8198,因此与第二个轴相比,第一个轴几乎不可见. daspect 可以解决此问题.

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不能选择用符号来绘制不同的图形.一种选择是编辑源代码以添加该功能(已在matlab中实现,您可以通过运行edit spy来获取源代码).不过,更简单的方法是分别监视正负部分:

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.

这篇关于如何在MATLAB中可视化稀疏矩阵?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆