Read sparse matrix from notepad

2 views (last 30 days)
Mark Sc
Mark Sc on 18 Jan 2022
Commented: James Tursa on 20 Jan 2022
Hi all,
I am trying to read a sparse matrix from a notepad.. I tried with the following matrix however, it's not given the correct sparse matrix:
clear all
clc
M=readmatrix('S_sp.dat');
I would like to the output to be as:
(1,1) 5.7744185
(1,2) 0.00
and so on...
I understand sprase should be without zero, but I need to read the file as it is , and be in a sparse format
I already attached the file in a zip folder
  2 Comments
Mark Sc
Mark Sc on 18 Jan 2022
@James Tursa Thank you so much for your comment,
I upload in .txt
The data in the file already sparse, I need to write it same, but with same format of sparse in matlab so I could use it later,
Hope you could help me...
Thank you,

Sign in to comment.

Accepted Answer

Matt J
Matt J on 18 Jan 2022
S=spconvert(load('S_sp.txt'))
  5 Comments
James Tursa
James Tursa on 20 Jan 2022
Note that these methods still have two copies of the data in memory, but as stated previously this probably can't be avoided in your case unless you resort to a mex routine.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by