Jump to content

Sub VI paradigm: Internal to a loop


Recommended Posts

Hey guys

I have a section of my code that I want to make into a sub vi, this sub vi would always be inside a loop and needs to use the index of the loop it's called from. I was wondering what the best paradigm would be to implement this. Is it as simple as making a terminal which takes the index or is there a better way of doing it?

Regards

Alex

Edit: For context and also because it leads me to another question. I'm trying to write a VI to raster a window through an image calculating the contrast in each section of the image. My image data currently exists as a 1D array so I've written my VI with this in mind, i.e. each time I shift the window I have to build the Region Of Interest (raster window) from the 1D data. I was wondering whether it would be smarter to cut the original 1D image data into rows, build a 2D array, and then raster a 2D sub window over the data?

Edited by AlexA
Link to comment

I have a section of my code that I want to make into a sub vi, this sub vi would always be inside a loop and needs to use the index of the loop it's called from. I was wondering what the best paradigm would be to implement this. Is it as simple as making a terminal which takes the index or is there a better way of doing it?

That sounds fine

Edit: For context and also because it leads me to another question. I'm trying to write a VI to raster a window through an image calculating the contrast in each section of the image. My image data currently exists as a 1D array so I've written my VI with this in mind, i.e. each time I shift the window I have to build the Region Of Interest (raster window) from the 1D data. I was wondering whether it would be smarter to cut the original 1D image data into rows, build a 2D array, and then raster a 2D sub window over the data?

I guess the questions I would ask here would be:

Is the window a moving window - or does each window contains mutually exclusive points from the 1D array?

Is the window length the same size each time (or determined another way)?

If it is a moving window you may find duplicating the points in memory is expensive and decreases performance.

Otherwise if its not, you would just be reshaping the array from a 1D to a 2D.

If the window lengths are not the same you may have to use e.g. a cluster, to protect the size of array (and end up with an array of clusters of arrays).

I guess the only way to tell will be to time both methods - if is not a moving window there is probably not much in it.

Link to comment

I don't know in what sense you mean moving but in my mind it is moving. As I imagine it the "window" is tracking across the data, effectively creating a subset of the data upon which the mathematics are performed.

In the current implementation of the code the data points are not mutually exclusive from one iteration to the next, the window shares all the same data points except for one new column. This is enormously expensive so I'm rewriting it to "tile" rather than raster. So the data points will be mutually exlcusive, i.e. the window will never share the same data points, in terms of the picture, the new window will be adjacent to the previous window rather than overlapping.

I hope this clarifies what I am trying to do.

I guess I'll try writing doubles of all my VI's, one for a 1D interpretation of the image data, and one for a 2D reconstruction. The 2D is more intuitive but I'm wondering if there will also be some sort of labview indexing trick that makes it more computationally efficient.

Edited by AlexA
Link to comment

Since you say this calculation is enormously expensive, I'd advise you NOT to make a sub VI inside a loop. At least, if your sub VI would also have its own loop(s). Instead, leave the two nested loops inside the same VI, perhaps by moving the outer loop to also be inside the sub VI. I once had speed issues with a VI, and called NI for help, and they advised me to move my outer loop inside the sub VI. I did, and that helped greatly.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.