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

Mathieu Dubois mathieu.dubois at limsi.fr
Thu Feb 11 19:37:00 CET 2010


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.
>>
>>
>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: test_gianluca.sce
URL: <https://lists.scilab.org/pipermail/users/attachments/20100211/9e1fd9f6/attachment.ksh>


More information about the users mailing list