using NearestNeighbors
using SparseArrays
using LinearAlgebra
radius=.03
box=[0,1,0,1]
ninit= 100
dotmax=1000
xx=range(0,stop=1,length=ninit)
yy=1e-4.*rand(1,ninit)
X=vcat(xx[:]‘,yy[:]’)
pdp = X’
pdp_end = ninit
p = zeros(dotmax,2)
t = pdp[1:pdp_end,2]
y = minimum(t)
a = argmin(t)
global d = 0
while y <= box[4] && d < dotmax
global d = d+1
p[d,:] = pdp[a,:]
end
Please have a look at this post: Please read: make it easier to help you . It explains how to ask a question, to make it easier for people to understand and answer.
What is the problem you have with this code? Anyway just trying to execute it, it fails on one of the first lines: pdp = [LinRange(box[1],box[2],ninit),box[3].+1e-4.rand(ninit,1)] because 1e-4.rand(ninit,1) doesn’t make sense. Do you mean 1e-4.*rand(ninit)?
1e-4.*rand(ninit)`,I wrote this correctly, it was copied incorrectly here
My problem is starting the while loop.This gives the error :
LoadError: UndefVarError: a not defined
I have no idea what you are trying to do so can’t answer that question. All I’m saying is that the code snippet in your original post (maybe after some edits you made?) runs fine, in the sense that all rows in p get filled with the row in pdp which has the lowest value in the second column. I don’t know whether this is what you’re after though.
Overall your code seems very convoluted and unnecessarily complex, are you coming from Matlab by any chance?
Yes I want to find the least value of the second column at the beginning of the code.
I have trained Julia for a while and I would like to learn it completely, but I used to work with MATLAB. Now I am going to convert a MATLAB code to Julia.I’m sure somewhere in the code is wrong because I do not get the output I get in MATLAB in Julia.This is the code output in Julia :
Matrix{Float64}(undef, 0, 2)
If the output is to be a vector that I draw and get the scatter points on the coordinate plane
to give the same result. However I have a strong suspicion that what you’re doing is suboptimal, as I struggle to think of a situation in which allocating a 1000x2 matrix which holds the same row 1,000 times is the best thing to do.
You can just post it here, as long as you format it correctly (i.e. in a block of triple backticks) it will render as code.
That said, just block posting some MATLAB code might not be the most productive thing to do - better to just ask specific questions about things you’re struggling with (e.g. “how do I conditionally overwrite certain rows of a matrix”) rather than giving people a big blob of code and asking “what’s wrong”.
That’s impossible to tell without an MWE really. But in principle it does sound like the sort of thing that simply running your code line-by-line and checking your output vector after every step should solve.
Depends on keymapping, but I think default is Ctrl+Enter or Shift+Enter to evaluate a single line.
Note that for a loop, Juno will automatically execute the whole code block if you evaluate any line in the loop, so you’ll have to select (highlight) the individual lines and Ctrl+Enter execute them.