"invalid assignment location" error

question

#1

Sorry ti all,
I’ve already posted a question for a real stupid error, but you…at the beginning…
Now I have another question…I’ve this simple code

function bn_dirichlet_prior(N)
n = length(N)
alpha = cell(n, 1);
for i = 1:n
[r, q] = size(N{i})
alpha{i} = ones(r, q)
end
return alpha
end

the error is
ERROR: LoadError: syntax: invalid assignment location
in expression starting on line 10
but the file has only 9 lines…!!!
This code was translated from MatLab
Thanks a lot


#2

Are you by any chance posting MATLAB code?


#3

Well…it was the result of the automatic translator…I know that Julia is very similar to MatLab…I was surprise that the code was almost identical…I checked with Julia manual and it made sense…
You mean that the code is completly out of Julia standard?


#4

Yes. Please read the manual.


#5

You want (r, q) = size(N[i]) or simply r, q = size(N[i]). Assignment to multiple left-hand sides in Julia uses a tuple (...), not an array [...]. Also, all indexing is done with [i], not {i}. (The Julia analogue of a Matlab cell array is a Julia Any[...] array … it is just an array of a different element type, but uses the same indexing syntax.)

Julia syntax is reminiscent of Matlab syntax in some ways, but the two are very different; you’ll need to learn it in order to use the language. Automated translation tools may take you part-way there, but even if automated translation is successful (as it clearly wasn’t here), an automatic translation to Julia is unlikely to yield fast code. You need to understand Julia and write Julia code in a slightly different style than you would in Matlab to get any performance benefit.


#6

You can’t assign like that. If you posted more of the error, it would’ve said that’s the line where you assigned incorrectly. That’s a pretty understandable error?

BTW, Julia doesn’t have (or need) cell. Julia is not MATLAB (nor would it ever want to be, given how limited MATLAB is!). You may want to read:

http://docs.julialang.org/en/release-0.4/manual/noteworthy-differences/#noteworthy-differences-from-matlab


#7

Thanks a lot to everybody…now the picture is clearer…and I need to review the time for preparing my utility: I need to learn Julia, even if I have a limited knowledge in MatLab.
My target was to integrate a MatLab utility which provides initial statistical condition for a montecatlo simulation I wrote in C++ code. I work in Linux and instead to wirk with MatLab, I work in Octave (adapting a little bit the MatLab code). The problem is that the Octave interpreter is very slow. At each iteration the creation of a new initial condition takes 6 time longer that the execution of the simulation, and the target is to run the simulation millions of times and even more, to demonstrate that an anticollision SW for unmanned aircraft has a failure rate less that some 10 -9. From that the idea to translate the MatLab/Octave utility in Julia, mach more efficient…but it hasn’t been so easy as I imagined…!!!
Thanks a lot again for your patience and tour input
Andrea