LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to access only the third dimension within a 3d array?

Solved!
Go to solution

ok so I have created an embedded for loop and need to access certain elements in each dimension of a 3d array in order for it to be manipulated. My 3d array is called 'u'. Below is the code in matlab and attached is my attempt:

ni and nj =201

 

PLEASEEEE HELPPPPP!!!!

 

1:(length(t)-1)
    for i=2:(ni-1)
        for j=2:(nj-1)    
            u(i,j,n+1) = ((u(i+1,j,n) + u(i-1,j,n) + u(i,j+1,n) + u(i,j-1,n))/4)...
                - 0.5*(dt/dx)*((u(i+1,j,n)^2)/2 - (u(i-1,j,n)^2)/2)...
                - 0.5*(dt/dy)*(v(i,j,n))*(u(i,j+1,n) - u(i,j-1,n)) - 0.5*g*(dt/dx)*(h(i+1,j,n)-h(i-1,j,n));

 

 

0 Kudos
Message 11 of 25
(1,323 Views)

You don't have a 3-D array in your VI, you only have a 1-D array.

 

Your VI doesn't even begin to resemble what your Matlab code looks like.  What are you really trying to do?

 

Look up "Autoindexing".  Also look up the function "Index Array".

0 Kudos
Message 12 of 25
(1,317 Views)

I know what is in the vi is 1d but it should be calling from the array u which is 3d I've attached it. Basically I want to recreate the matlab code into labview but aI have no idea of how to go about it, I understand that index array is needed but not sure how to apply it, would I need to use it for each bracket in the equation? Or could it be used once?

 

P.S. I posted twice because I'm desperate.

0 Kudos
Message 13 of 25
(1,314 Views)

I don't know what you are referring to by "each bracket in the equation".

 

It looks like you are trying to take an existing 3-D array modify it based on other values in it.

 

Your 3-D array should go into the 3 For Loops with shift registers at each and every time the 3-D array crosses a For Loop border.  This maintains the values of the 3-D array as they change.

 

Inside the innermost For loop you put the code that you are doing in your innermost For Loop in you matlab code.  Index array will access the different elements.  Use the i value from each For Loop with as is, or with the increment (+1) or decrement (-1).  Use Replace Array Subset to change the element in your 3D array to its new value based on the result of your equation.

 

I don't know where your dt/dx and dt/dy values are coming from in your equation.

0 Kudos
Message 14 of 25
(1,310 Views)

the dt, dx and dy are pre-defined, there values which have already been found in the codeing, how would i use the index array i.e. where would i wire the row, col and pages elements too? i didnt understand the second part of your reply, could you re-expalin it please?

 

"Use the i value from each For Loop with as is, or with the increment (+1) or decrement (-1).  Use Replace Array Subset to change the element in your 3D array to its new value based on the result of your equation."

 

also thank you very much for helpin me out

0 Kudos
Message 15 of 25
(1,307 Views)
Solution
Accepted by topic author sbash123

I really don't want to do the work for you, but I feel like you still have enough work to do that I can create a sample of what you need to do.

 

Notes:.

 

  1. This is a simple example that is just averaging togther the i-1, i, and i+1 elements at the inner most For Loop.
  2. You'll have to pay attention to indices.  For Loops are zero based on the iteration terminal.  It looks like some of your loops you start at 2, so you will have to account for that.  (I didn't in my example.)
  3. This code is going to get really complicated really quick with the number of terms in your equation.  Create a subVI for the code in the inner most loop.  Pass in your array, your i values, and your other constants such as dx/dt, pass out the updated 3-D array.
  4. This may even get so complicated that you may want to skip using pure LabVIEW code for the equation but do the math for the equation in a formula node.
  5. I don't know how your i, j, and n terms will match up with row, column, and page dimensions.  So they may not be in the correct order in my example, but then again, I didn't try to program the whole equation in my example.
  6. Do good documentation.  Put labels in your loops so that you know which is your i loop, which is the j, and which is the n.  LabVIEW 2011 even allows labels on wires now, so that would help keep wires from being confused.

 

Message 16 of 25
(1,304 Views)

One poroblem is i cannot open you example as your version of labview is too advanced i am using is 2010.

 

Regards

0 Kudos
Message 17 of 25
(1,301 Views)
0 Kudos
Message 18 of 25
(1,299 Views)

could you please tell  me if my attempt at solving the first line of codeing within the for loop is correct?i.e. the section highlighted in bold below

 

for n=1:(length(t)-1)
    for i=2:(ni-1)
        for j=2:(nj-1)    
            u(i,j,n+1) = ((u(i+1,j,n) + u(i-1,j,n) + u(i,j+1,n) + u(i,j-1,n))/4)...
                - 0.5*(dt/dx)*((u(i+1,j,n)^2)/2 - (u(i-1,j,n)^2)/2)...
                - 0.5*(dt/dy)*(v(i,j,n))*(u(i,j+1,n) - u(i,j-1,n)) - 0.5*g*(dt/dx)*(h(i+1,j,n)-h(i-1,j,n));

 

 

0 Kudos
Message 19 of 25
(1,283 Views)

also how could i go about adjusting it to add in the remaining code???

 

0 Kudos
Message 20 of 25
(1,281 Views)