From: Chris on
I'm trying to use triu to extract the data in the upper part of a very big matrix. Every iteration I have to move the position of the diagonal. The rate and memory limiting bottleneck in my coding appears to be the actual triu part of the script, and I can't see how the code works to try and change it (edit triu doesn't help here as it's a built-in function). So I was wondering if anyone knows?

My code is:

P=full column length of matrix (>20,000)
ppart=portion of matrix
xa=diagonal moving variable
D=my data

D=sparse(D(((triu(ones(P,ppart),((xa)*-1))))==1));

I believe the line (triu(ones(P,ppart)) actually creates a full matrix of ones before applying the triu, I want to avoid doing that.