Prev: qr economy LaPack
Next: How to set the seed as a 128 binary string of psudo random number generator (randn)
From: sscnekro on 8 Jun 2010 06:06 > That _doesn't_ work...to see, try > 1: [1,5,8,17] : 20 Tried in the meantime. You are right. Thank you.
From: Steven Lord on 8 Jun 2010 13:19 "sscnekro " <stiahni.mail(a)zoznam.sk> wrote in message news:hujpvg$86b$1(a)fred.mathworks.com... >> What's the problem perceived problem/novelty? > > No, no, there is no novelty. It's just that I first hit on this yesterday > and when writing a code I myself personally would easily mix up using such > step values with a reference on some places in the code that assumes > increment of size one. > > This is what I started to imagine yesterday is meant by hlp doc, that one > would be able of setting for s = initval: [1,5,8,17] : endval so that s > would take values initval, initval + 1, initval +1+ 5, etc. until endval > is reached. If you wanted to do something like that, you could use CUMSUM: initval = 0; steps = [1 5 8 17]; endval = 16; s = [initval initval+cumsum(steps)]; % If you stepped too far, get rid of the extra elements s(s>endval) = [] % and if you want the last element of s to be exactly endval % s = [s endval]; Note that whether or not you want to perform the last step depends on your expectations. If you want to agree in spirit with the behavior of the colon operator you would not do this, as that operator does not guarantee that the last element of the resulting vector is the b that you specify when you call it (using the naming convention given in HELP COLON): x = 1:2:10 % x is [1 3 5 7 9] not [1 3 5 7 9 10] > PS dpb, don't let confuse yourself by some of my posts written from a > commercial product customer's point of view, with my posts on programming > and using ML. I know where my place is on the newsgroup wrt the latter. > For you as an 'Old Guy' (old in the sense of huge programming and problem > solving experience) there will never be novelty in my posts. No one is so experienced that they can't sometimes be surprised or learn something new. -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
From: sscnekro on 8 Jun 2010 16:06 > If you wanted to do something like that, you could use CUMSUM: > ... Hi, many thanks for the well explained examples, I find them useful for myself and maybe many other readers have learned too.
First
|
Prev
|
Pages: 1 2 3 Prev: qr economy LaPack Next: How to set the seed as a 128 binary string of psudo random number generator (randn) |