[英]Extract the Compressed Column Storage vectors from MATLAB sparse matrix
I have the following matrix in MATLAB. 我在MATLAB中有以下矩阵。
A =
1 3 0 2 0
0 1 0 0 2
0 0 4 0 0
1 0 0 0 4
0 2 0 2 0
I can get the triplet form from using the sparse(A)
command but is there a built in way to get the column_pointer, row_index and the values from MATLAB or should I write the code? 我可以通过使用
sparse(A)
命令来获取三元组形式,但是是否有内置的方法可以从MATLAB获取column_pointer,row_index和值,还是应该编写代码? (I have a working code in C++ to convert from triplet to Compressed Column Storage which I have to port over to a .m file, I presume) (我想我在C ++中有一个工作代码,可以将三元组转换为压缩列存储,我想必须将其移植到.m文件中)
MATLAB's find()
still gives triplet form. MATLAB的
find()
仍给出三元组形式。 But I want the compressed column storage form as shown below. 但是我想要压缩的列存储形式如下所示。 (MATLAB is 1 index based. So the i think both col_ptr and row_index might be incremented by 1)
(MATLAB基于1索引。因此,我认为col_ptr和row_index都可能增加1)
col_ptr = [0 2 5 6 8 10];
row_index = [ 0 3 0 1 4 2 0 4 1 3]
values = [ 1 1 3 1 2 4 2 2 2 4]
I think this does it: 我认为这样做:
col_ptr = [0 cumsum(sum(A~=0,1))];
[row_index, ~, values] = find(A);
row_index = row_index.'-1;
values = values.';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.