f



is there any fast find or index like find in matlab

Hi,

I'd like to merge 2 matrix A (100000 x 300)
and B (60000 x 1), along the row identified
by the cell strings rA, rB resp.
I've tried to use the function "find" to
construct the resulting row index, but it's
slow. So my question: is there any faster
way to manage that ? thx, hugo
0
hugo552 (23)
2/15/2004 3:49:34 PM
comp.soft-sys.matlab 211266 articles. 13 followers. lunamoonmoon (258) is leader. Post Follow

8 Replies
325 Views

Similar Articles

[PageSpeed] 48

hugo wrote:
>
>
> Hi,
>
> I'd like to merge 2 matrix A (100000 x 300)
> and B (60000 x 1), along the row identified
> by the cell strings rA, rB resp.
> I've tried to use the function "find" to
> construct the resulting row index, but it's
> slow. So my question: is there any faster
> way to manage that ? thx, hugo

Hi.

I'm not sure that i got your problem right.

But may be you can try to construct proper 0 & 1 matrices from your
cell strings.
than to multiply those new matrices by your A and B.
And from the result to get buck the desired form.

It's not always can be implemented, but when it can - it use much
more computations but runs FASTER.

candid
0
candid_s (7)
2/15/2004 4:51:24 PM
hugo <hugo@hotmail.com> wrote:

> I'd like to merge 2 matrix A (100000 x 300) and B (60000 x 1),
> along the row identified by the cell strings rA, rB resp.

What do you mean by "merge"?  And what is a cell string?

Peter

-- 
If I make a copy of the The Digital Millennium Copyright Act,
would that be a violation of it?        -- me
0
pjacklam (309)
2/15/2004 5:49:51 PM
Peter J. Acklam wrote:
>
>> I'd like to merge 2 matrix A (100000 x 300) and B (60000 x 1),
>> along the row identified by the cell strings rA, rB resp.
>
> What do you mean by "merge"? And what is a cell string?
>

to be more clear: rA and rB are cell array
of strings which identify the rows of A and
B, rA and rB have some common intersetion.
By "merge", I simply mean constructing
a new matrix by "cat" the columns of A and
B, in respecting the rows identification:
same id of A and B give the same row,
outsider will be assigned with sth like nan.
thanks in advance, hugo
0
hugo552 (23)
2/15/2004 5:59:50 PM
"hugo" <hugo@hotmail.com> wrote in message
news:eed0760.-1@webx.raydaftYaTP...
> Hi,
>
> I'd like to merge 2 matrix A (100000 x 300)
> and B (60000 x 1), along the row identified
> by the cell strings rA, rB resp.
> I've tried to use the function "find" to
> construct the resulting row index, but it's
> slow. So my question: is there any faster
> way to manage that ? thx, hugo

If you can provide the code that is slow, it will make it clearer what you
are trying to do and we may be able to make it go faster.



0
rob2828 (210)
2/15/2004 6:13:31 PM
Rob Henson wrote:
>
>> I'd like to merge 2 matrix A (100000 x 300)
>> and B (60000 x 1), along the row identified
>> by the cell strings rA, rB resp.
>> I've tried to use the function "find" to
>> construct the resulting row index, but it's
>> slow. So my question: is there any faster
>> way to manage that ? thx, hugo
>
> If you can provide the code that is slow, it will make it clearer
> what you
> are trying to do and we may be able to make it go faster.
>

based on the function find, just a loop:

rC = rA ;
for i=1:size(rB,1)
  d = find(strcmp(rA, rB(i))) ;
  if isempty(d)
    d = size(rA,1) + 1 ;
    rC(end+1) = rA(i) ;
  end
  idx(i) = d ;
end

with idx it's then trivial for the
construction of the result matrix.
0
hugo552 (23)
2/15/2004 7:01:02 PM
perhaps Rob Henson has forgoten to answer me, any help ?

Rob Henson wrote:
>
>> I'd like to merge 2 matrix A (100000 x 300)
>> and B (60000 x 1), along the row identified
>> by the cell strings rA, rB resp.
>> I've tried to use the function "find" to
>> construct the resulting row index, but it's
>> slow. So my question: is there any faster
>> way to manage that ? thx, hugo
>
> If you can provide the code that is slow, it will make it clearer
> what you
> are trying to do and we may be able to make it go faster.
>

based on the function find, just a loop:

rC = rA ;
for i=1:size(rB,1)
  d = find(strcmp(rA, rB(i))) ;
  if isempty(d)
    d = size(rA,1) + 1 ;
    rC(end+1) = rA(i) ;
  end
  idx(i) = d ;
end

with idx it's then trivial for the
construction of the result matrix.
0
hugo552 (23)
2/26/2004 12:19:33 AM
hugo <hugo@hotmail.com> wrote in news:eed0760.5@webx.raydaftYaTP:

> perhaps Rob Henson has forgoten to answer me, any help ?
> 
> Rob Henson wrote:
>>
>>> I'd like to merge 2 matrix A (100000 x 300)
>>> and B (60000 x 1), along the row identified
>>> by the cell strings rA, rB resp.
>>> I've tried to use the function "find" to
>>> construct the resulting row index, but it's
>>> slow. So my question: is there any faster
>>> way to manage that ? thx, hugo
>>
>> If you can provide the code that is slow, it will make it clearer
>> what you
>> are trying to do and we may be able to make it go faster.
>>
> 
> based on the function find, just a loop:
> 
> rC = rA ;
> for i=1:size(rB,1)
>   d = find(strcmp(rA, rB(i))) ;
>   if isempty(d)
>     d = size(rA,1) + 1 ;
>     rC(end+1) = rA(i) ;
>   end
>   idx(i) = d ;
> end
> 
> with idx it's then trivial for the
> construction of the result matrix.

Can you provide examples of rA and rB?

Are rA and rB cell arrays filled with strings? If do, why don't you use 
curled braces, which makes at least the code much easier to read.

Maybe intersect will be of some use?

Jos

-- 
Email: jnvdg AT arcor DOT de

0
jos6178 (52)
2/26/2004 10:38:15 AM
Jos wrote:
>
>
> hugo <hugo@hotmail.com> wrote in
news:eed0760.5@webx.raydaftYaTP:
>
>> perhaps Rob Henson has forgoten to answer me, any help ?
>>
>> Rob Henson wrote:
>>>
>>>> I'd like to merge 2 matrix A (100000 x 300)
>>>> and B (60000 x 1), along the row identified
>>>> by the cell strings rA, rB resp.
>>>> I've tried to use the function "find" to
>>>> construct the resulting row index, but it's
>>>> slow. So my question: is there any faster
>>>> way to manage that ? thx, hugo
>>>
>>> If you can provide the code that is slow, it will make it
> clearer
>>> what you
>>> are trying to do and we may be able to make it go faster.
>>>
>>
>> based on the function find, just a loop:
>>
>> rC = rA ;
>> for i=1:size(rB,1)
>> d = find(strcmp(rA, rB(i))) ;
>> if isempty(d)
>> d = size(rA,1) + 1 ;
>> rC(end+1) = rA(i) ;
>> end
>> idx(i) = d ;
>> end
>>
>> with idx it's then trivial for the
>> construction of the result matrix.
>
> Can you provide examples of rA and rB?
>
> Are rA and rB cell arrays filled with strings? If do, why don't you
> use
> curled braces, which makes at least the code much easier to read.
>
> Maybe intersect will be of some use?
>
> Jos
>
> --
> Email: jnvdg AT arcor DOT de
>
>

For example, rA and rB could be two list of
person names or some other more "official"
identification ids (eg. passport number).

The operation I wand to do is very similar
to "join" 2 tables along with an common id
column in a relational database, and it's
fast there, as the common id column
are "indexed" before.

What I'd like to know was is there some mecanisme in Matlab to
performe
that sort of "join" efficiently.

Any idea/help ?
0
hugo552 (23)
2/26/2004 8:06:19 PM
Reply: