I’m trying to call a function(.jl) in a folder. terminal reported a bug:
"MethodError: no method matching getindex"
Attached text you find the test code:
NxNy = Nx*Ny
ii =(i-1)*Nx + j*Ny
ccc[ii] =c0 + ii*NxNy
# main function
c0 = 0.2
ccc = testc[Nx,Ny,c0]
Thanks in advance!
You are using square brackets
testc[Nx, Ny, c0] in calling your function when you should be using round brackets
testc(Nx, Ny, c0)
I seem to remember that you are transitioning from Matlab - I think you’ll find with time that this is one of the key day-to-day improvements working in Julia compared to Matlab. Whereas Matlab uses round brackets both for indexing (e.g.
my_array(1:5)) and function calls (e.g.
my_function(argument)), in Julia square brackets are reserved for indexing and function calls work with round brackets, making the likelihood of introducing bugs by confusing the two a lot lower!
such results came from https://lakras.github.io/matlab-to-julia/
[out1,out2,…,outn] = functionname(arg1, arg2, …, argn)
[out1,out2,…,outn] = functionname[arg1, arg2, …, argn]
Many many thanks for your support!
I would recommend against using any of this type of automatic conversion tool. As you can see, they don’t really work and in the end it will likely take longer time to use the tool than to do it manually. Also, if you want to program in Julia you still need to learn the language, and rewriting a program in another programming language is a great way to learn.
sure, you are fully correct!!
I agree with @kristoffer.carlsson, although to make life easier for people who still want to use the translator I’ve filed an issue here.
The translation is fundamentally impossible because you don’t know if the symbol is a function or an array by just parsing the code.
This was discussed with @Aquaman previously, to apparently little effect.
@Tamas_Papp , I used your suggested web ( tools, eg this one , translate a subset) to test a very very simple function, previously, to apparently little effect.
Please do not misrepresent what I said — as clarified in that topic, I never suggested that you use this tool, or any other.
That said, you are of course free to ignore advice from multiple experienced Julia users, but this case is a perfect demonstration of why translation tools will not help you. You would be much better off just learning Julia.