Question:
IDL question please help!?
Scandolous
2012-01-26 05:18:22 UTC
I have the following code:

centre = replicate(10, n_elements(distance))
a0=1
b0=2
a and b are both values in an array
distance = (((a - replicate(a0,n_elements(d)))^2 * (cos(b0)^2)) + (b - replicate(b0,n_elements(dec)))^2)^(1/2)

f = where(distance GT r2)
plot, a(f), b(f)

error: array dimensions greater than 0

I think this is because I can't compare an array with both a variable and an array in the same where statement. If this is the case, what is the alternative?
PLEASE HELP!!
Four answers:
?
2012-01-26 05:28:34 UTC
the answer is 42, remember splitting sublim lines is always wrong unless you add a factor of 9
permeative pedagogy
2012-01-26 14:33:33 UTC
It's been a while since I've seen you ask an IDL question.



Your code is a bit difficult to work through because I have no idea what a lot of your variables are. On another note, your error should tell you what line the error is on. But it looks to me that your error comes in your calculation of distance. You claim that a and b are both values in an array, but then you have the bit:



a - replicate(a0,n_elements(a))



So it seems to me that you are attempting to subtract an array of size n_elements(1) from the number a. This isn't really allowed because you cannot subtract an array from a number. You can however subtract a number from every element of an array. You then go on to square that operation which in itself doesn't make sense. How do you square an array?



Possibly you are misunderstanding what the command replicate(val, D1,...D8) does. In case you don't know it creates an array whose dimension sizes are specified by D1 through D8 and it fills every position in the array with val. Such that if you used replicate(1, 5, 5) it would make a two dimensional, 5 by 5 array where each value in the array was 1.



Hope that helps.
bestonnet_00
2012-01-26 13:49:22 UTC
Been a while since I last used IDL (and I don't have it around anymore) but it should tell you what statement it is getting an error at and then a bit before you can play with the print and help commands to get some extra information to check that the variables you're putting into the statement are what they should be (though print tends to produce a lot of output with arrays, but filling up the can sometimes help).
Lola F
2012-01-26 13:34:27 UTC
What are "d" and "dec?" Do they have the same dimensions and a and b? I think you're probably ending up with a distance array of different dimensionality than a and b, and end up referencing cells that don't exist in them. I would check "distance" to make sure it is what you think it is.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...