04-20-2012 02:02 PM
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));
04-20-2012 02:26 PM
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".
04-20-2012 02:42 PM
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.
04-20-2012 03:03 PM
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.
04-20-2012 03:10 PM
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
04-20-2012 03:35 PM
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:.
04-20-2012 03:42 PM
One poroblem is i cannot open you example as your version of labview is too advanced i am using is 2010.
Regards
04-20-2012 03:45 PM
LV2010
04-21-2012 04:24 AM
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));
04-21-2012 04:29 AM
also how could i go about adjusting it to add in the remaining code???