File Exchange

image thumbnail

Sparsity pattern

version (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 (2021). Sparsity pattern (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (4)

Wolfgang Schwanghart

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

Pascal Schulthess

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.

Wolfgang Schwanghart

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);

Pascal Schulthess

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
Tags Add Tags

Community Treasure Hunt

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

Start Hunting!