Re: URGENT!! Referencing a matrix from another vector



one way would be to create a logical matrix, t= a==1. Then use repmat
to creat t2 = [t t]. Multiply t2 with b, i.e. c = t2.*b. Now you can
remove the rows with zeros, c(all(c,2)==0,:)=[]
While not elegant, I think it will do the job. (i'd love to know any
better ways there are)

sushma

charles benzinger wrote:


Hi,

This is a follow up to a question I posted earlier:

Suppose I have a 9x1 matrix a = [ 1 2 2 4 2 1 1 5 1]'. Let b=
rand(9,2).

I want to create matrix c (n x 2) matrix, where the first column in
c
are the elements in teh first column of b where a==1. I want the
second column to be elements in teh second column of b where a==1.

I have tried c = b(a==1), but that returns one column of outpur (it
stacks the two columns I want into one).
Any help would be appreciated!!!

cb
.



Relevant Pages

  • Re: how can i read formatted data from string?
    ... lin = fgetl; ... I am sure there are more elegant ways to read the formatted text, though ... First Column = Date ... Second Column = Hour ...
    (comp.soft-sys.matlab)
  • URGENT!! Referencing a matrix from another vector
    ... I want to create matrix c matrix, where the first column in c ... are the elements in teh first column of b where a==1. ... second column to be elements in teh second column of b where a==1. ... stacks the two columns I want into one). ...
    (comp.soft-sys.matlab)
  • Re: URGENT!! Referencing a matrix from another vector
    ... I want to create matrix c matrix, where the first column in c ... are the elements in teh first column of b where a==1. ... second column to be elements in teh second column of b where a==1. ... Steve Lord ...
    (comp.soft-sys.matlab)
  • Re: Memory Error while constructing Compound Dictionary
    ... > For the purpose of illustration let's suppose that the first column ... suppose the second column contains a ... this is a prelude to complicated meta-hack programming of the type Python ... in which case you either need a larger machine or a database. ...
    (comp.lang.python)
  • Re: Sorting two columns of data
    ... you can record a small macro to cut the second column ... and paste it to the bottom of the first column, then select it and sort, ... > My intent was to be able to import data from a database and have the sort ...
    (microsoft.public.excel.worksheet.functions)