Reputation: 808
Hello i am trying to draw a function with Gadfly using Julia. I have no problem with function like this:
function F(x)
return x+5
end
I use plot(F,1,10)
and it works.
Unfortunately for this function which is returning elements of an array it doesn't work:
function F(x)
return myArray[x]
end
I would be grateful for telling me where it goes wrong.
Upvotes: 1
Views: 88
Reputation: 5746
If you want to create an Index-Value plot of myArray
elements I think the correct usage is:
plot(y=myArray,x=1:10)
and if you want to create a piecewise continuous plot, then declaration of f(x)
should be something like this:
function F(x::Float64)
global myArray
return myArray[floor(Int,x)] # or myArray[round(Int,x)] or myArray[ceil(Int,x)]
end
Upvotes: 1