您的位置:首页 > 编程语言 > MATLAB

matlab常用函数

2016-07-27 13:47 281 查看
spy

spy

matlab自带的spy函数只能实现对稀疏矩阵的非0值绘制,也就是,无法实现“矩阵不同值对应不同颜色”,为了实现这个功能,可以对matlab自带的spy函数进行简单的更改,即

将spy.m中的如下部分

[i,j] = find(S);
if isempty(i), i = NaN; j = NaN; end
if isempty(S), marker = 'none'; end
plot(j,i,'marker',marker,'markersize',markersize, ...
'linestyle',linestyle,'color',color);


更改为

[i,j,ss] = find(S); % Note we need the values of the nonzeros as
% well as their indices
if isempty(i), i = NaN; j = NaN; end
if isempty(S), marker = 'none'; end
scatter(j,i,markersize,ss,'filled','o');#此处将marker style写死了


例子

clc
clear
close all

x1 = random('Uniform',0,11,10,10);
spy1(x1,200) #这里可以指定maker的大小
colorbar
box on


结果



存在的问题

这样更改后存在一个小问题,无法指定用什么marker style,只能在spy中写死
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  matlab 函数