[scilab-Users] help needed for a grep in a multidimensional struct array

Gianluca Antonelli antonelli1970 at gmail.com
Thu Feb 11 21:20:40 CET 2010


Thanks a lot, it works fine!

I'll have to think about changing all over the code the type for my 
variable-to-be-searched but I probably will.

Best,
g.


Mathieu Dubois wrote:
> Hello Gianluca,
> 
> Do you really need a multidimensional struct array?
> 
> I have tried to replace the struct array with a mlist (see attachment). 
> I don't know much about Scilab' struct or mlist but this example works 
> (see Scilab help).
> 
> Two caveats:
>  - array=="abc" doesn't work with multidimensional arrays (why?) so I 
> use array(:)=="abc"
>  - find therefore return a linear index that I can convert back to 
> subscripts thanks to ind2sub
> 
> A bit scilabic but it works!
> 
> Hope that helps, Mi auguro che aiuta,
> Mathieu
> 
> Le 11/02/2010 14:37, Gianluca Antonelli a écrit :
>> Dear Mathieu,
>>
>> thanks for your reply.
>>
>> I tried the synthax you suggest and the output is always empty. Below a
>> simple code to verify it.
>>
>> I know that it is very simple to build a customized grep-like function
>> but my real 3-dimensional struct array is quite large and I'm worried
>> about computational time.
>>
>> Here is a not-working sample code:
>>
>> -----------------------
>> -->N=10;for i=1:N; for j =1:N; for k=1:N; slot(i,j,k).cdl="";
>> slot(i,j,k).modulo=""; end; end; end
>>
>> -->slot
>> slot =
>>
>> 10x10x10 struct array with fields:
>> cdl
>> modulo
>>
>> -->slot(1,2,3).cdl="abc";
>>
>> -->find(slot.cdl=="abc")
>> ans =
>>
>> []
>> ----------------------
>>
>> Best,
>> g.
>>
>>
>>
>> Mathieu Dubois wrote:
>>> Hello Gianluca,
>>>
>>> Did you try a simple:
>>> find(slot.cdl=="abc")
>>>
>>> It should not be difficult to turn this in a function...
>>>
>>> Mathieu
>>>
>>> Gianluca Antonelli wrote:
>>>> 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.
>>>
>>>
>>




More information about the users mailing list