08-11-2011 09:32 AM
Hi
Is there any way except using while or for loops for creating constant arrays? In fact i need to create different constant arrays thier value start from 0 till k with increament steps equal 1(where k is different for different itteration of my program).
Using itteration loops will slow down my program and won't be desirable. is there any way other, which do this task with a fraction of time(more speedy than itteration loop ?
with regards
08-11-2011 09:39 AM
ramp pattern
08-11-2011 10:09 AM
Starting with a blank VI. create whatever algorithm you need (e.g. a for loop) to generate the array, sending it to an indicator.
Run the VI to populate the array indicator.
On the block diagram, right-click the array indicator and select Change to Constant.
Copy the constant to the VI where you need it.
08-11-2011 10:51 AM - edited 08-11-2011 10:55 AM
farashi wrote:Is there any way except using while or for loops for creating constant arrays? In fact i need to create different constant arrays thier value start from 0 till k with increament steps equal 1(where k is different for different itteration of my program).
Using itteration loops will slow down my program and won't be desirable. is there any way other, which do this task with a fraction of time(more speedy than itteration loop ?
FOR and WHILE loops will not slow down your code unless something else is terrribly wrong (e.g. you are doing it wrong or you are filling all available RAM). How are you doing it? How big are the arrays?
All you need is a FOR loop with N wired as desired and [i] wired to an autoindexing output tunnel.
You would be able to do the following if you know an upper limit for the size: make it once using a FOR loop using all diagaram constant as parameters. This will cause the array to be folded into a constant and calculated before the program even starts. To create shorter arrays if needed, use array subset or reshape array. It won't be much faster that recreating it from scratch. (I also doubt that "ramp pattern" will give you any advantage over a simple FOR loop in this case).
My guess is that you don't even need these arrays. What are you trying to actually do?
(Creating an array diagram constant is also not desireable for large arrays, because it will seriously inflate the size of the VI on disk).
08-11-2011 10:53 AM
Thanks for your reply. but as i mentioned my desirable constant array will be changed in different itteration of my code, so i need an automatic method which get the last number(k) and construct constant array from 0 to k . using itteration tools like for or while is time consuming so will destroy my program which need to be executed in real time.
regards
08-11-2011 11:01 AM
@farashi wrote:
using itteration tools like for or while is time consuming so will destroy my program which need to be executed in real time.
What is you definition of "real time"? What makes you think that such loops are time consuming? Unless you are running on an FPGA, CPUs need to iterate anyway to populate the entire array, you cannot magically fill many memory locations at once. Show us some code!
The most expoensive part is allocating the memory, which, using a FOR loop is trivial because the size is known from the beginning.
You still have not told us about the array sizes involved.
08-11-2011 11:07 AM
Hi altenbach ,and thanks for your reply
as you mentioned, for and while loops will be executed very fast in labview but the problem is that ,the length of my data (constant array) is too long . I fact i have a long length data, which i wanna extract its peak and then interpolate between extracted peaks in a manner that the length of result and main data be equal.This act will be repeated for several times , but it is possible that the length of main data decrease or increase. so the large length of data will be a problem for real time execution of my code,
thanks
08-11-2011 11:10 AM
That still does not explain why you need an array ramp at all. Compared to all other operations finding a peak and interpolating, creating a ramp is neglibly fast and irrelevant in the overall process. Trust me.
As I said, show us some code!
08-11-2011 11:13 AM
Hi frashi,
I suggest yo utake Christian up on his offer to look at your code. He is one of the best developers of fast efficient LV code the world has ever known. You will be passing up a great oppertunity if you do not let him look.
Ben
08-11-2011 12:43 PM
Thanks altenbach for your reply,
Let me to give you the overall view of my program. I have a variety of codes contains several VIs include Data acquisition, data analyzing and data displaying. My codes are linked to each other by global variable i.e data acquired with be delivered to data analyzing VI with global variable and so on . one important issue in my code is that when my card is triggered , before the next trigger all of analyzing and displaying purposes must be accomplished so i prefer not to use of iteration loops(FOR loop) if there is other solutions be possible. a small part of my program is attached below if can help for better solution!(don't forget my data has long length and this part will be executed about 100 times in a second)
Thanks