Path: news.mathworks.com!not-for-mail
From: "Megan " <m.evans1@uq.edu.au>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Build a new vector using relational query within a script
Date: Sat, 26 Jun 2010 04:19:05 +0000 (UTC)
Organization: University of Queensland
Lines: 32
Message-ID: <i03v3p$k$1@fred.mathworks.com>
References: <i03f7l$42e$1@fred.mathworks.com> <i03tbg$8fo$1@fred.mathworks.com>
Reply-To: "Megan " <m.evans1@uq.edu.au>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1277525945 20 172.30.248.37 (26 Jun 2010 04:19:05 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 26 Jun 2010 04:19:05 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2361145
Xref: news.mathworks.com comp.soft-sys.matlab:648173

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i03tbg$8fo$1@fred.mathworks.com>...
> "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

Hi Roger and Matt,

I used the A and B matrices to indicate how such an operation would play out using Access, but it seems to have made things more confusing. I do actually mean  c = B(:,1), not  c = B(:,2) - but let's ignore A and B since a,b and c are the inputs I"m interested in. The output of my function is pu_sparse_TU.
So a = indices of interest, b = corresponding values, c = indices of interest but expanded (part of a sparse matrix), and the indices in c don't repeat in a predictable pattern. I want the values in b to be expanded according to c, following the matching rules between a and b.

Cheers, Megan