Hi,
I have the following problem.
I have the following variable:
slot =
30x5x10 struct array with fields:
modulo
cdl
I need to find all the indexes for which the field cdl matches a
specific grep command.
I would like to know if is it possible to have a function such as:
out = grep(slot.cdl, "abc")
Any hint?
Thanks in advance,
g.
|
|
0
|
|
|
|
Reply
|
antonelli1970 (1)
|
2/11/2010 9:03:07 AM |
|
ga a �crit :
> Hi,
>
> I have the following problem.
>
> I have the following variable:
>
> slot =
>
> 30x5x10 struct array with fields:
> modulo
> cdl
>
> I need to find all the indexes for which the field cdl matches a
> specific grep command.
>
> I would like to know if is it possible to have a function such as:
>
> out = grep(slot.cdl, "abc")
>
> Any hint?
>
> Thanks in advance,
> g.
>
>
if slot.cdl contains only single strings
grep(cat(1,slot.cdl(:)),'abc') //will do the job
explanation:
slot.cdl is a list each list element contains one string.
slot.cdl(:) is the sequence of individual strings
so cat(1,slot.cdl(:)) is equivalent to
cat(1,slot.cdl(1),slot.cdl(2),...,slot.cdl($))
and the result is a vector of strings. so one can apply the regular grep
on it
A more general solution can be to define the %l_grep function as follow
function k=%l_grep(l,key)
k=[]
for i=1:size(l)
if type(l(i))==10 then
ki=grep(l(i),key)
if ki<>[] then k=[k,i],end
end
end
endfunction
Serge Steer
INRIA
|
|
0
|
|
|
|
Reply
|
Serge
|
2/15/2010 12:55:24 PM
|
|