File Exchange

image thumbnail

Sparsity pattern

version 1.0.0.0 (1.32 KB) by Pascal Schulthess
Apply sparsity pattern of one matrix to another.

1 Download

Updated 19 Apr 2010

View License

OutPatternMatrix = sppattern(InPattern,InMatrix)

OutPatternMatrix - Output Matrix
InPattern - Target sparsity pattern
InMatrix - Matrix to apply sparsity pattern to

Cite As

Pascal Schulthess (2019). Sparsity pattern (https://www.mathworks.com/matlabcentral/fileexchange/27292-sparsity-pattern), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

I am glad this helped! I hate to give bad ratings. Good luck with your work!

Haha, this is not what i hoped to get as response, but I was searching for a solution which is as simple as yours. And I ended up with this complicated script. D'oh! Thanks for this.

As a result, I will delete my script.

To be honest, I am not quite sure what this function is supposed to do different from this statement:
OutPatternMatrix = spones(InPattern).*InMatrix;

Your function help doesn't help much to clarify.

Moreover, your function returns an error for following example:
>> InPattern = sprand(5,5,0.4);
>> InMatrix = sprand(5,5,0.4);
>> OutPatternMatrix = sppattern(InPattern,InMatrix)
??? Error using ==> sparse
Vectors must be the same lengths.

Error in ==> sppattern at 30
OutPatternMatrix = sparse(iP,jP,sT,m,n);

This is a fast coded first version. Please contact me for problems or suggestions for improvement.

MATLAB Release Compatibility
Created with R2007b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Tags Add Tags