On 24 September 2011 17:33, JuanPi <ajua...@gmail.com> wrote: > Hi > > >From a discussion in the IRC channel concerning this post > http://stackoverflow.com/questions/242711/algorithm-for-index-numbers-of-triangular-matrix-coefficients/3148414#3148414 > > JordiGH improved the algorithm and include it in sprandsym, though he > mentioned that there may be problem with rounding real numbers. > Therefore user deeego proposed the use of lookup. JorgdiGH mentioned > that the two version had similar profiling times and that deego's > suggestion was more robuts cause it doen't suffer form rounding > problems. I wrote the function and I post it here > > function [r c] = ind2sub_triu (N, idx) > endofrow = (1:N) .* (N - (0:(N - 1)) / 2); > r = lookup(endofrow, idx-1)+1; > > c = N - endofrow(r) + idx; > end > > %!test > %! A = [1 2 3 4; 0 5 6 7; 0 0 8 9; 0 0 0 10]; > %! [r c] = ind2sub_triu (rows(A),1:10); > %! A_shouldbe = accumarray([r; c]',1:10); > %! assert (A,A_shouldbe) > > %! assert(A,) > > Why to add this function?
I kind of like the idea of adding this as a "triu" or "tril" option to sub2ind (and to ind2sub). I'm CC'ing the maintainers list to see if this could be done or if it's a dangerous idea. - Jordi G. H. ------------------------------------------------------------------------------ All the data continuously generated in your IT infrastructure contains a definitive record of customers, application performance, security threats, fraudulent activity and more. Splunk takes this data and makes sense of it. Business sense. IT sense. Common sense. http://p.sf.net/sfu/splunk-d2dcopy1 _______________________________________________ Octave-dev mailing list Octave-dev@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/octave-dev