On Saturday, 31 January 2015 01:09:47 UTC-5, Jung Soo Park wrote:
>
> I am generating two functions and the outcome of the first function will
> be use as input values of the second function.
>
> Like Matlab's case of [x,y,z] =test_function(input), I used Julia's tuple
> function to generate [x,y,z] and it worked well.
>
> function test_function(input)
> x=rand(20,5);
> y=rand(30,50);
> z=rand(5,100);
> ALL=tuple(x,y,z);
> return ALL
>
You don't need to write "tuple" or "ALL", simply "return (x, y, z)" will
also do ("return x, y, z" will mean the same thing). The semicolons and the
ends of lines are also unnecessary.
> end
>
> I sliced the output of ALL with [[ ]] and save as xx,yy,zz.
>
> ALL= test_function(best)
> xx=ALL[[1]];
> yy=ALL[[2]];
> zz=ALL[[3]];
>
This is where this is going wrong. Compare:
julia> x = (1, 2, 3)
> (1,2,3)
> julia> x[[1]]
> (1,)
> julia> x[1]
> 1
julia> x[[1,1]]
> (1,1)
When you write ALL[[1]], you are not getting the first element of a tuple,
you are getting a tuple of length 1 (the length of the array [1]), whose
first component is ALL[1], the first component of ALL.
The error message then tells you the the size of a tuple is not defined:
notice the extra pair of parentheses and a trailing comma.
By the way, it's possible to write "xx, yy, zz = test_function(best)",
without using a temporary variable.
> But I found the size of original output (say x) and sliced (say xx) are
> not identical so I can not transfer the values into the second function.
> size(x)
> (20,5)
>
> size(xx)
> `size` has no method matching size(::(Array{Float64,2},))
>
> while loading In[1], in expression starting on line 12
>
>