You can then use spconvert to import the sparse matrix directly. it comes from another program you have written) it would make much more sense to save only the non-zero elements in the format row_idx, col_idx, value. I don't know where this data has come from, but if you have any control over its creation (e.g. See this answer for some examples.Īs I say above, the method your matrix is saved as is pretty inefficient – for a matrix with 10% sparsity, around 95% of your text file will be a zero or a space. You can fairly easily write your own spy function, which can have different coloured or sized points depending on the values at each location. If it does, then it's going to cause you memory problems.Īll spy is really doing is plotting in 2D the locations of the non-zero elements. With regards to visualisation: visualising a sparse matrix like this via a tool like imagesc is possible, but I believe it may internally create the full matrix – maybe someone can confirm if this is true or not. % add row to sparse matrix (note transpose, which I think is required) Sparse_matrix = sparse(num_rows, num_cols) Try something like: (untested code!) % initialise sparse matrix You can find out if this is possible by estimating the sparsity of your matrix, and using this to see if the whole thing could be loaded into MATLAB's memory as a sparse matrix. In your case, however, it would make sense to read in the text file, one line at a time, and convert to a MATLAB sparse matrix on-the-fly. Answers (0) Sign in to answer this question. The traditional way of doing this would be to load it all in at once, then convert to sparse representation. Walter Roberson on Theme Copy cat (3, firstband, secondband, thirdband) but since all of your data is probably in a 3D array, just extract Theme Copy bands 17 53 58 for example combinedbands YourHyperImage (:, :, bands) Sign in to comment. However, I suspect that as long as it is sparse enough, it can still be leaded into MATLAB as a sparse matrix. If your matrix is sparse, then it seems that the currently method of storing it (as a full matrix in a text file) is very inefficient, and certainly makes loading it into MATLAB very hard.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |