Read sparse matrix from notepad
10 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Mark Sc
am 18 Jan. 2022
Kommentiert: James Tursa
am 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 Kommentare
James Tursa
am 18 Jan. 2022
Bearbeitet: James Tursa
am 18 Jan. 2022
Can you provide a small sample of numbers in a txt or mat file instead of a zip file? Also, the sparse format in MATLAB does not store 0's. Trying to create such a matrix, even using hacks, would only result in an invalid sparse matrix and would violate assumptions made in background sparse matrix operations. Why do you think you need to physically store 0's in your sparse matrix?
Normally one would read in the data and then generate the sparse matrix from this data, which unfortunately results in two copies of the data in memory. The only ways I know of to read data directly into a sparse matrix would be to use a mex routine or to have the data in a mat file (e.g., text version) already in sparse format. Is the size of the matrix and the number of elements known prior to reading the elements?
Akzeptierte Antwort
Matt J
am 18 Jan. 2022
S=spconvert(load('S_sp.txt'))
5 Kommentare
James Tursa
am 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Resizing and Reshaping Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!