简体   繁体   中英

sparse triplet to sparse matrix matlab

What command can I use to convert a sparse triplet into a sparse matrix in MATLAB? I've been trying this one: B=st_to_msm(A) , where A is my sparse triplet read from a ".dat" file, and B is just some variable.

It's not working for me, though. I want to know how to fix it or if there's another command to do the conversion.

MATLAB has only 2D sparse matrices and thus 3D addressing won't work for sparse matrices.

You may want to check N-dimensional sparse arrays in MATLAB Central File Exchange .

The code for st_to_msm is http://people.sc.fsu.edu/~jburkardt/m_src/st_to_msm/st_to_msm.m

  [ nrow, ncol, nnzero ] = st_header_read ( input_file );
  [ row, col, a ] = st_data_read ( input_file, nrow, ncol, nnzero );

  base0 = 0;
  base1 = 1;
  row = st_rebase ( base0, base1, nnzero, row );
  col = st_rebase ( base0, base1, nnzero, col );
  b = sparse ( row, col, a, nrow, ncol, nnzero );

In other words, it reads dimensions, and 3 vectors from the file, and uses them as arguments to the sparse function. I suspect your A consists of those 3 vectors, row , col , a . Look at the documentation for sparse for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM