OutPatternMatrix = sppattern(InPattern,InMatrix)
OutPatternMatrix - Output Matrix
InPattern - Target sparsity pattern
InMatrix - Matrix to apply sparsity pattern to
Pascal Schulthess (2019). Sparsity pattern (https://www.mathworks.com/matlabcentral/fileexchange/27292-sparsity-pattern), MATLAB Central File Exchange. Retrieved .
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.