LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Simulation

Thank you all very much. I actually were able to simulate these rotating "lines" (moleculse) as I wanted. All I have left to do is to optimize my code, so it will be easier to read and obviously faster. I will make some of the corections you suggested. I attach my present code. 

Download All
0 Kudos
Message 11 of 15
(801 Views)

I applied some of your suggestions and I'll attach it here

Download All
0 Kudos
Message 12 of 15
(800 Views)

@Silly_student wrote:

I applied some of your suggestions and I'll attach it here


Sigh!

 

OK, I got LabVIEW 2018 running on my laptop and I am now able to look at your code. Unfortunately, you have two missing subVIs so I can't even run it. Does it work?? (doubt it!)

 

Some important observations (that you have ignored in my earlier advice!)

  1. Local variable misuse. A local variable is not a variable in the classic text programmer sense. It is just points to the data currently held in the terminal. Reading from a terminal and writing to a local variable of itself does nothing except wasting resources and diagram space. You are reading from a local variable in parallel to writing to its terminal. In general that can cause serious race conditions, because the outcome might depend on what happens first, but the order is not predictable. Things might even execute in parallel on different CPU cores. (You are safe because the value does not change if you write to itself, but it is still extremely ugly). Similarly, you read these local variables in two more places outside the main loop, that means even if the controls are changed by the user the new values are never used. Dataflow! They get read before the loop starts and never again. Inside the loop you'll just get the stale value from the tunnel. Eliminate all locals and just wire from the terminal. If you want them to be read in the main loop, that's where the terminals belong!

LocalMisuse.png

 

 

I already mentioned your matrix initialization and you made it even worse! Now the outer output tunnel is "last value" so all earlier iterations are discarded.  You are lucky that the "reshape matrix" will pad with zeroes. I have no idea why you think that you need to covert that matrix to a matrix using "array to matrix". Completely pointless. Does your current code produce the correct matrix based on size selection? If it is correct, here's a simpler alternative. (IF it is incorrect, please tell us how the matrix should look like! Other requirements can easily be equally simple) (Note that I eliminated the locals).

 

MatrixInit.png

 

Again, you are not doing any linear algebra, so please keep it as a 2D array! Don't convert to a matrix! A matrix has a very special meaning in LabVIEW. It is basically a typedef'd 2D array that silently changes certain operations. Definitely not what you want here!

 

 

 

 

 

 

 

 

 

0 Kudos
Message 13 of 15
(786 Views)

I must have attached the wrong code, because I already changed the initializing of the matrix. Even though I missuse the term of local variables, it is still better for me to use some, except wiring everything through the whole block diagramm. I think I stay with the matrix type of the angles, simply because it is working correctly now so I think there's no need in changing it. Still thank you very much for your time and help!!

Download All
0 Kudos
Message 14 of 15
(773 Views)

@Silly_student wrote:

I must have attached the wrong code, because I already changed the initializing of the matrix.


Please don't re-use filename when attaching new code. My downloads folder e.g. already has a "Draw_matrix.vi", so the newer version will be renamed to "Draw_matrix(1).vi" by the browser and the caller will only find the stale version. This is very annoying!

 

If you re-use filenames, Please place all files into a zip file before attaching so they can be unzipped to a new folder, limiting the problem somewhat (unless an older VI with the same name is still in memory). If you make it too complicated for us, nobody will help.

 

Even if you put the files into a zip archive, give them new names! Sometimes we want to compare old and new versions side-by-side and that's not possible if everything has the same name.

0 Kudos
Message 15 of 15
(769 Views)