CLM
CLM

Reputation: 13

Problem with Julia function - output not displaying double difference

I am new to julia and am trying to create a function in which calculates a double difference between events for a set of receivers and puts all these double differences into a vector, however my function output is this

(::var"#d#8 {Array{Float64,2},Array{Float64,2},Int64,Int64}) (generic function with 1 method)

Here is the code:

function doubledifference(obsEvents, calcEvents)
    I = size(obsEvents, 2) #event 1
    J = size(obsEvents, 2) #event 2
    K = size(obsEvents, 1) #receiver
    M = ((K*I)*(K - 1))/2
    M = Int(M)
    d = zeros(M, 1)
    n = 1 #d position counter
    for i = 1:I #i.e. no. columns in matrix
        for j = 1:J
            for k = 1:K
                if j <= i
                    j = j + 1
                else d(n) = (obsEvents(k, i) - obsEvents(k, j)) - (calcEvents(k, i) - calcEvents(k, j))
                    n = n + 1
                end
            end
        end
    end
    
    return d
end

Upvotes: 1

Views: 42

Answers (1)

phipsgabler
phipsgabler

Reputation: 20960

That's pretty alright, because it is the printed output of the function.

d(n) = (obsEvents(k, i) - obsEvents(k, j)) - (calcEvents(k, i) - calcEvents(k, j))

declares a local function, aka closure, with an anonymous type var"#d#8, and parameter n, which internally calls other functions (!) obsEvents and calcEvents. The function name d shadows the array d. That function is returned.

Julia is not Matlab. Array indexing uses square brackets:

d[n] = (obsEvents[k, i] - obsEvents[k, j]) - (calcEvents[k, i] - calcEvents[k, j])

Upvotes: 1

Related Questions