A simple MATLAB program for reading and writing text files-sparse matrix vector multiplication

Source: Internet
Author: User

% Matrix vector multiplication, written to the file <br/> % dual for loop. It has been running for a long time and needs to be improved, <br/> clear <br/> CLC <br/> N = 150000; % matrix dimension <br/> A = sprand (N, N, 0.0001 ); % generate a sparse matrix <br/> fid1 = fopen ('matrix. gmt', 'w'); % matrix file to be written <br/> fid2 = fopen ('matrix _ B. gmt', 'w'); % Vector file <br/> disp ('1') <br/> Len = nnz (); % Number of non-zero elements in the sparse matrix <br/> disp ('2') <br/> fprintf (fid1, '% d/N', N, N, len); % number of rows, columns, and non-zero elements <br/> disp ('3') <br/> for j = 1: n <br/> for I = 1: n <br/> If a (I, j )~ = 0 <br/> fprintf (fid1, '% d % F/N', I, j, a (I, j )); % file written in triple format <br/> end <br/> disp ('4') <br/> fprintf (fid2, '% d/N', n); <br/> B = sprand (n, 1, 0.9); % generates a sparse vector <br/> disp ('6 ') <br/> for I = 1: n <br/> fprintf (fid2, '% d/N', B (I, 1 )); % write vector <br/> end <br/> disp ('5') <br/> S = a * B; <br/> full_s = Full (s ); % convert the result into a matrix <br/> Save s.txt full_s-ASCII % Save the result of matrix vector multiplication <br/> fclose (fid1); <br/> fclose (fid2 );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.