我创建了一个sparseMatrix,并使用writeMM将其保存为MatrixMarket格式--稀疏矩阵自动更改为ngTMatrix类(来自dgCMatrix)。我使用readMM重新加载它,并绘制矩阵。一切都很好,除了我不能使用简单的xlim,ylim来控制轴。如果我目前只对能够控制轴感兴趣,那么解决方案是什么?
示例代码
a = sparseMatrix(i=c(1,2,3),j=c(9,5,7),x=1)
image(a,ylim=c(0,4)) # ylim Works!
writeMM(a,'test.mtx')
b = readMM('test.mtx') #b now belongs to ngTMatrix class
image(b,ylim=c(0,4)) # ylim does not work !发布于 2013-11-29 15:39:15
dgCMatrix是一个标准数字矩阵(描述),而ngTMatrix是一个二进制真/假逻辑矩阵(描述)。
> print(a)
3 x 9 sparse Matrix of class "dgCMatrix"
[1,] . . . . . . . . 1
[2,] . . . . 1 . . . .
[3,] . . . . . . 1 . .
> print(b)
3 x 9 sparse Matrix of class "ngTMatrix"
[1,] . . . . . . . . |
[2,] . . . . | . . . .
[3,] . . . . . . | . .乘以1强制逻辑矩阵为数字,绘图将起作用:
> print(b*1)
3 x 9 sparse Matrix of class "dgCMatrix"
[1,] . . . . . . . . 1
[2,] . . . . 1 . . . .
[3,] . . . . . . 1 . .
> image(b*1, ylim=c(0,4))或者,您可以使用as()函数,如本帖子所示。
https://stackoverflow.com/questions/20284065
复制相似问题