稀疏矩阵图matlab [英] Sparse matrix plot matlab

查看:375
本文介绍了稀疏矩阵图matlab的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个5000 * 5000的稀疏矩阵,有4个不同的值。我想用4种不同的颜色可视化非零元素,这样我就可以识别这些值的比例和它们之间的关系,我使用 imagesc ,但我不能很好地认识到不同的值,尤其是比率较小的值。我想如果我为每个值使用一些符号,它可以工作,但我不知道它是如何在Matlab中。有什么建议吗? Dan代码的结果如下图所示。

I have a 5000 *5000 sparse matrix with 4 different values. I want to visualise the nonzero elements with 4 different colors such that I can recognise the ratio of this values and the relationships between them,I use imagesc but I can not recognise very well among different values, especially the values with smaller ratio.I think if I use some symboles for each value , it works but I don't know how is it in Matlab. Any suggestion? The result of Dan code is in figure below.

推荐答案

你可以将矩阵改造成一组[X,Y,F]坐标(重新使用我的答案来自重新采样矩阵并在一个矩阵中恢复):

You could reform the matrix to be a set of [X, Y, F] coordinates (re-using my answer from Resampling Matrix and restoring in one single Matrix):

假设您的矩阵 M

[X, Y] = meshgrid(1:size(M,1), 1:size(M,2));
Mf = M(:); %used again later, hence stored
V = [X(:), Y(:), Mf];

摆脱零元素

V(Mf == 0, :) = [];

此时,如果您有权访问统计工具箱,可以去 gscatter(V(:,1),V(:,2),V(:,3))以获得正确的绘图,否则如果您没有工具箱则继续以下操作:

At this point, if you have access to the statistics toolbox you can just go gscatter(V(:,1), V(:,2), V(:,3)) to get the correct plot otherwise continue with the following if you don't have the toolbox:

查找M中唯一值的列表

Vu = unique(V(:,3));

对于每个这样的值,将点绘制为xy散点图,注意保持所有确保颜色每次添加新绘图时都会更改,即循环的每次新迭代

For each such value, plot the points as an xy scatter plot, note hold all makes sure the colour changes each time a new plot is added i.e. each new iteration of the loop

hold all;
for g = 1:length(Vu)
    Vg = V(V(:,3)==Vu(g),:)
    plot(Vg(:,1), Vg(:,2), '*');
    a{g}=num2str(Vu(g));
end
legend(a);

示例 M

M = zeros(1000);
M(200,30) = 7;
M(100, 900) = 10;
M(150, 901) = 13;
M(600, 600) = 13;

结果:

这篇关于稀疏矩阵图matlab的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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