On Friday, June 29, 2012 01:28:32 PM thomaslai wrote:
> I was porting my matlab code and was wondering what is the best way to
> replace the functionalities provided by the matlab cell arrays.
As others have said, cell arrays in Matlab are Arrays of type Any in Julia.
While the {a,b} syntax will surely be familiar to you, be aware that you index
them with [] just like all other arrays in Julia (i.e., not like Matlab's ()
for arrays and {} for cell arrays).
> The context
> is as belows:
>
> I have a custom type opKron that takes in multiple objects of another
> custom type opMatrix, and the constructor should look like this, opKron(
> opMatrix, opMatrix,.... ) with as many opMatrices as the user desires. For
> this i need three functionalities:
>
>
> 1. The ability to accept variable number of input arguments.
> - Normally I just have to use opKron(varargin) in matlab. Now I know
> that opKron(op1,ops...) works in Julia but then this gives me op1 of
> type opMatrix and ops which is a tuple. This breaks my cell array into
> ungainly pieces which brings us to the next problem.
Try opKron(ops::opMatrix...)
Then the whole argument list will be a single tuple
>
> 2. The ability to "uncell" and recombine
> - Normally in matlab all I need to do is: newOpsArray = {op1, ops{:}
> } and I will get a new non-nested cell array, emphasis on non-nested,
> as I need to index into this array for future processing.
To amplify further on Jeff's points:
julia> c1 = "Hello"
"Hello"
julia> c2 = ("how", "are", "you")
("how","are","you")
julia>
julia> c = [c1, c2...]
4-element ASCIIString Array:
"Hello"
"how"
"are"
"you"
julia> typeof(c1)
ASCIIString
julia> typeof(c2)
(ASCIIString,ASCIIString,ASCIIString)
julia> typeof(c)
Array{ASCIIString,1}
julia> cc = {c1, c2...}
4-element Any Array:
"Hello"
"how"
"are"
"you"
julia> typeof(cc)
Array{Any,1}
> In Julia I have
> tried all possible symbols and functions to "uncell" the tuple and scoured
> all possible documentation for any hints but this uncellibility and
> unconcatenatibility of tuples still vex me.
It took me a while too. At one point I started writing some exercises (plus
answers) for the manual, I should try to get those merged.
--Tim