Thanks again, seams to be working. Will test it more tomorrow.
sábado, 16 de Julho de 2016 às 02:42:56 UTC+1, Chris Rackauckas escreveu:
>
> Oh, I guess it's just with most of the Base types you can do that (they
> must have internal constructors for it). The convert issue comes up because
> you have type checks on your fields, i.e. ::Type, otherwise you could just
> make an internal constructor which calls new(nothing,nothing). No sweat,
> you can just make an internal constructor:
>
> D() = new(Array{Float64,2}(),string())
>
> (or anything like that). Since your Type is not mutable, you can just
> overwrite what you put in there.
>
> On Friday, July 15, 2016 at 6:37:54 PM UTC-7, J Luis wrote:
>>
>> Thanks. Didn't know one could create empty types,, but is it a 0.5
>> feature. Because on 0.4
>>
>> julia> Di=D()
>> ERROR: MethodError: `convert` has no method matching convert(::Type{D})
>> This may have arisen from a call to the constructor D(...),
>> since type constructors fall back to convert methods.
>>
>>
>>
>> sábado, 16 de Julho de 2016 às 02:28:30 UTC+1, Chris Rackauckas escreveu:
>>>
>>> Well, you just made the type D, so you can make Array{D,n} or anything
>>> else like that. The Base types are not special in Julia, anywhere you can
>>> use a type, you can use your own.
>>>
>>> You can create an empty form of your type via dinstance = D(). You can
>>> then add to it by setting dinstance.data = someMatrix; dinstance.header =
>>> "hi!". In fact, you can make a whole array of empty D's by Darr = [D() for
>>> i in 1:N] and then set the fields in a loop by Darr[i].data = someMatrix.
>>> You might want to read the documentation on type for more details.
>>>
>>> If you need the fields to be mutable, you can make one of the fields in
>>> the type be a dictionary and use that, or you can use a cell array (I think
>>> these may be deprecated?)
>>>
>>>
>>> On Friday, July 15, 2016 at 6:14:26 PM UTC-7, J Luis wrote:
>>>>
>>>> Hi,
>>>>
>>>> I need to mimic what in Matlab is called a struct matrix. e.g.
>>>>
>>>> >> D=struct('data',{rand(2,2);rand(2,2)},'text',{'aa';'bb'})
>>>>
>>>> D =
>>>>
>>>> 2x1 struct array with fields:
>>>>
>>>> data
>>>> text
>>>>
>>>>
>>>> in MEX I would use (and actually that's what I do in the C MEX code
>>>> that I'm trying to port)
>>>>
>>>> mxCreateStructMatrix()
>>>>
>>>> For one single of this it's easy
>>>>
>>>> type D
>>>> data::Array{Float64,2}
>>>> header::ASCIIString
>>>> end
>>>>
>>>> but how do I create an array of D's?
>>>> And probably worst, I need to fill them with the data that comes from a
>>>> ccall(). So not only I do not know to create the array as I have no idea
>>>> either on how fill it since one cannot create empty types and fill them in
>>>> loops.
>>>>
>>>> Thanks
>>>>
>>>