matlab - spy 与颜色 Matlab

标签 matlab sparse-matrix spy

引用这篇之前的帖子 Getting different colors for different numbers using `spy` in Matlab

有人提出以下建议,以便用不同的颜色表示不同的 spy 值

spy(a,'k')
hold on
spy(a==10,'r')
spy(a==9,'b')
hold off

如果我想使用 RGB 定义怎么办?例如,所有元素 =10 的 [0.6 0.2 0] 和所有元素 =9 的 [0.8 1 0] 而不是已经定义的 r、b 和 k 等?

以下不起作用,因为所有 Spy 矩阵都将具有某种颜色,

set(get(gca,'children'),'color',[0.6 0.2 0])

谢谢, M.

最佳答案

您非常接近解决方案。 children 为三个输入中的每一个返回三个结果,您必须对其进行索引。

x=get(gca,'children')
set(x(1),'color',firstcolor)
set(x(2),'color',secondcolor)
set(x(3),'color',thirdcolor)

关于matlab - spy 与颜色 Matlab,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35485139/

相关文章:

matlab - 如何在 MATLAB 中检索选定的文本?

python - 从字典子集有效填充 SciPy 稀疏矩阵

python - 将 python 稀疏矩阵导入 MATLAB

java - 给定网格的一些节点,查找飞机在网格上的位置

c++ - 运行 Simulink 模型来生成 C/C++ 代码进行编译

matlab - 对多个属性使用一个 set 方法 MATLAB

c# - 使用 Moq (C#) 监视对象

java - 一起使用@Spy 和@Autowired

reactjs - Jest 进行 spy 事件时出现类型错误 : Cannot set property getRequest of#<Object> which has only a getter

matlab - 矩阵的值在其边缘周围平滑地下降到零