Path: news.mathworks.com!not-for-mail From: <HIDDEN> Newsgroups: comp.soft-sys.matlab Subject: Re: Build a new vector using relational query within a script Date: Sat, 26 Jun 2010 03:49:04 +0000 (UTC) Organization: The MathWorks, Inc. Lines: 24 Message-ID: <i03tbg$8fo$1@fred.mathworks.com> References: <i03f7l$42e$1@fred.mathworks.com> Reply-To: <HIDDEN> NNTP-Posting-Host: webapp-05-blr.mathworks.com Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Trace: fred.mathworks.com 1277524144 8696 172.30.248.35 (26 Jun 2010 03:49:04 GMT) X-Complaints-To: news@mathworks.com NNTP-Posting-Date: Sat, 26 Jun 2010 03:49:04 +0000 (UTC) X-Newsreader: MATLAB Central Newsreader 1187260 Xref: news.mathworks.com comp.soft-sys.matlab:648170 "Megan " <m.evans1@uq.edu.au> wrote in message <i03f7l$42e$1@fred.mathworks.com>... > ....... > where c = B(:,1) > ...... > while c(h,1)==b(j,1); > ..... - - - - - - - - - After taking a more careful look at your "create_pu_sparse_TU" function, I appear to have misunderstood what your c vector is. When you stated c = B(:,1) I think you meant c = B(:,2). The values of c in the function are apparently the 0's and 1's that are found in b = A(:,2), as evidenced by the condition "c(h,1)==b(j,1)" and not the indices that are found in a = A(:,1), so my code wouldn't work. For your function to make any sense, the b vector must alternate at each row and the c vector must be expansions of each of these single values. That is, in the example you gave, b = [0;1;0] and c = [0;0;1;1;1;0;0] then consists solely of various numbers of repetitions of each element in b, two of the first, three of the second, and two of the third. If this is the case, there is no need to even access b since it has to be assumed to alternate at each row. It is possible to write code which accomplishes this in one line, based on that assumption: d = a(cumsum([true;diff(c)~=0])); However, I question the appropriateness of doing it this way. The very process that allowed you to do such an expansion of b into c is very likely to have provided you with a much better way of producing the required indices in vector d. I think you need to rethink your explanation of what you are trying to do so that it can make better sense to others of us in this newsgroup. Roger Stafford