Programmatically Resizing 'Decimate Array'
I am using Labview 6i. Is it possible to programmatically resize the
'Decimate Array' function? I've got a bunch of data to display in a graph
and want no more than say 1000 points displayed. I want to only look at
every other point if I have more than 1000 points and every third point if I
have more than 2000 points, etc... Is there an easy way to accomplish this?
Thanks,
Peter
You an find a vi in the palette Analyze/Signal processing/timedomain.
This one does what you want and is called ! decimate array.vi! The function you seem to recall is called decimate 1D array.
An easier way to find this particular one is to use FIND in the palette. Click on the magnifier glass and type dec and you find both the function and the vi.
greetings from the Netherlands
Similar Messages
-
How do I programmat​ically modify array element sizes?
Hi All,
I have a quick question about modifying the size of array elements. Hopefully someone can help, because I am at a dead end!
I am logging some intensities from a Fibre Array using a camera. For calibration of the system, I acquire an image from the camera, click points on the image to divide it into areas of interest. I overlay my image with a grid showing the regions of interst - for example a 4x6 array. I then have to select the fibres - or ROIs - I want to log from.
I have a cluster type-def ( a number and a boolean) to specify the fibre number and to turn logging from that fibre on/off. I overlay an (transparent) array of this typedef over my image to correspond with the regions of interest. So here's my problem - I want to modify the dimensions of the array so each control matches my ROI. I can resize the elements by rightclicking on the elements on the frontpanel, but can't find a way to do it programmatically. The Array Property Node>>Array Element>>Bounds won't 'change to write'...thats the first thing I tried.
Its really only important that the elements align with my ROIs - so programmatically adding in gaps/spacings would also work for me...but again I can't figure out how to do this! I've attached a screenshot of part of my image with array overlaid to show you all exactly what my problem is.
Thanks in advance for you help,
Dave
PS I am running Labview 8.6 without the vision add on.
Solved!
Go to Solution.
Attachments:
Array_Overlay.png 419 KBHere's my cheat (and cheap?) way If you want to get fancy and center the numeric and boolean indicators, you could add spacers on the north and west sides, too.
Attachments:
ClusterSpacer.vi 13 KB -
Resizing an array of struct inside a DLL using the memory manager
Hi all,
I dug deep inside the boards, but wasn't able to find a solution for my problem.
I'm building a dll, which does some imageprocessing and should return an array of structs to labview, with one struct for every element in the image.
As I don't know the number of elements beforehand and the limit of the number is numbers of magnitude larger then the expected one, I don't want to allocate such a huge chunk of memory prior to the dll call in labview.
In a former version I used a 2d array for the elements, where each row holds the values of every element. Here I used the NumericArrayResize-function, which worked quite well. But I have to add more sub-processes and using structs (or clusters in labview) appears to be more usefull and cleaner for me, in addition I had to cast some of the elements back and foreward a few times.
So one element-struct should hold 2 singles and 1 uint32. My question is now, how can I resize this array of struct with memory manager functions as the NumericArrayResize-functions does not suit this purpose?
(Accessing a given array of structs inside the DLL and after that reading the changed values in Labview is surprisingly easy )
Thanks in advance
Solved!
Go to Solution.Well, I was able to solve it myself. I found this thread, where the first post of rolfk made me thinking. It appeared to me, that the numericarrayresize-function behaves very similar to the realloc-function of c. So I used the type unsigned int 8 (which is just one byte) and multiplied it by the number of bytes used by one struct, in my case 12 bytes (4+4+4) and then multiplied it by the number of structs (elements in the image) i have. Luckily it worked and the memory block was resized exactly as I wanted it to be. Important to note: do not forget to adjust the size element of the handle, otherwise Labview does not know about the changed size.
-
How can I resize an array of strings?
I'm having a problem of not being able to use the CIN functions and therefore can't use the convenient resizing methods. I have tried to use NumericArrayResize to resize an array of strings, but it's not working correctly. Here's what I've tried most recently. I have tried many variations, so if you want to modify what I have posted, or just provide new code, please feel free.
typedef struct {
int32 dimSize;
LStrHandle elt[1];
} LStrHandleArray;
typedef LStrHandleArray **LStrHandleArrayHandle;
void someMethod(LStrHandleArrayHandle arrayOut) {
// attempting to write the string "asdf" in the first element in the array. (1D array)
int newSize = 1;
MgErr e = NumericArrayResize(uL, 1L, (UHandle*)&arr
ayOut, newSize);
(*arrayOut)->dimSize = newSize;
LStrHandle hdl = *(*arrayOut)->elt;
long str_size = strlen("asdf");
MgErr err = NumericArrayResize(uB, 1L,(UHandle *)&hdl, str_size);
LStrLen(*hdl) = str_size;
MoveBlock("asdf", LStrBuf(*hdl), str_size);
The code above doesn't result in crashing labview at any time. The string "asdf" is not copied though. And, after being able to copy one string I would like to extend this to many elements in a 1D array of strings.
Thanks!
NaveenLabVIEW stores string arrays as an array of handles to those strings. To resize an array of strings you need to declare a new string in LabVIEW's data space, resize the handle array, and add a handle to your new string. Here is an example program which does this.
-Aaron Marks
National Instruments
Attachments:
resize.zip 252 KB -
Hi,
Is it possible to resize an array of objects ? I create an array of 10000 objets. But I need ,after more calculations , only 8000 objects. Is it possible to resize the original array without create another array and copy the original in the new array ?
Thank you for your help
MarcelNo, you cannot resize arrays in java.
The simplest thing to do is use one of the List implementations. ArrayList and LinkedList both provide
the appearence of resizable structures. (ArrayList contains an array which it automatically resizes for you
(by copying) which LinkedList is inherently dynamic in size (but slow to perform indexed get operations
on)
matfud -
Resizeing an array of LStrHandles within Call Library Functio Node crashes SubVI.
Hello,
I try to resize an array of LStrHandles within a shared library. Here the C-code - attached a picture of the calling SubVI:
/* Call Library source file */
#include <stdio.h>
#include "extcode.h"
/* Typedefs */
typedef struct {
long dimSize;
LStrHandle elt[1];
} TD1;
typedef TD1 **TD1Hdl;
long strArray(TD1Hdl arg1);
long strArray(TD1Hdl arg1)
long err=0, count=2;
err = DSSetHandleSize((UHandle)arg1, sizeof(long) + count*sizeof(LStrHandle));
if(err) {
printf("ERROR: 'DSSetHandleSize()': %ld\n", err);
return err;
(*arg1)->dimSize = (*arg1)->dimSize;
return noErr;
I know there are a lot of threads, I read some and also tried the provided source code but somehow LabVIEW crashes. I don't know if it is valueable but when I change the following line it does not crash:
(*arg1)->dimSize = (*arg1)->dimSize;
Thanks for any help,
Johannes
OS: RedHat
LV: 8.2 Prof
Message Edited by [email protected] on 03-11-2009 12:26 PM
Solved!
Go to Solution.
Attachments:
subvi-resize-stringarray.jpg 7 KBTo be honest I'm not fully sure why that would crash but proper dealing is a lot more complicated than what you have done. The crash probably happens not in the C fucntion but on return of the function as LabVIEW tries to display the data. DSSetHandleSize() does not initialize the area it allocates additionally so there is likely garbage which LabVIEW then tries to interpret as string handles and consequently crashes.
You should also use NumericArrayResize() whenever possible as it takes care of various complications that can be hard to deal with on multi platform programs. NumericArrayResize() does use internally DSSetHSzClr() which initializes additional memory to 0. That would avoid the crash since LabVIEW does interpret NULL handles as the default for the according datatype, which would be here an empty string.
#include "extcode.h"
#if IsOpSystem64Bit
#define uPtr uQ
#else
#define uPtr uL
#endif
typedef struct {
int32 dimSize;
LStrHandle elm[1];
} TDStrArr, **TDStrArrHdl;
MgErr MyArrayFunc(TDStrArrHdl arr)
int32 count = 4;
LStrHandle p;
MgErr err = noErr;
/* The array could be non empty so dispose of any elements in it that are bigger than what we need */
for (i = (*arr)->dimSize - 1; i >= count; i--)
p = (*arr)->elm[i];
if (p)
DSDisposeHandle(p)
(*arr)->dimSize = i + 1;
/* resize the array handle to get enough space */
err = NumericArrayResize(uPtr, 1, (UHandle*)&arr, count);
if (err)
return err;
/* Fill in the data as desired */
for (i = 0; !err && i < count; i++)
p = (*arr)->elm[i];
#if !complicated
err = NumericArrayResize(uB, 1, (UHandle*)&p, 1);
#else
if (p)
err = DSSetHSzClr(p, sizeof(int32));
else
p = DSNewHClr(sizeof(int32));
if (p)
(*arr)->elm[i] = p;
else
err = mFullErr;
#endif
if (!err)
err = LStrPrintf(p, "%ld", i);
(*arr)->dimSize = i;
return err;
Rolf Kalbermatter
Message Edited by rolfk on 03-11-2009 08:40 PM
Rolf Kalbermatter
CIT Engineering Netherlands
a division of Test & Measurement Solutions -
Hello:
My name is Juan Crespo, and I write you from Spain. I have a problem with a Labview application I am developing. I hope you could help me.
In my application, I read an interleaved array from a text file, the number of single arrays that are interleaved is variable, but user must put this number in a numerical control. I wanted the application to decimate the interleaved input array into arrays and then show a graph displaying all the arrays.
My problem is as follows: I have a LV block that I thought useful to my application ("Decimate 1D array"). But this block dont allow to set from a control the number os arrays in which the interleaved one must be divided. Dont you know any way in order to divide an interleaved array in a set of arrays, where the number of elements of this set must be provided from a control?
Well, I thank you very much for your attention... and, please, sorry for my bad english.
Yours Sincerely
Juan CrespoHello Juan. How are things in Spain? You can set the number of output arrays by resizing the decimate function. See the attached vi. You have to do this at development time. You cannot do this using a control for the number of arrays and have the function resize at runtime. Maybe you could use a case structure and connect the control to the case. In each case you could have a decimate function that is properly sized. See attached vi, lower section. Hope this helps.
- tbob
Inventor of the WORM Global
Attachments:
Decimate.vi 74 KB -
How can I resize an array directly (without using reshape array)?
Hi everyone,
I have a porgam in which I am using an array as a command (with specific values that the user enters before running the program). By mistake, at the beginning I created a 4 dimension array (for instance), but I didn't know because I was only showing the first 3 values (not expanding the array to 4 or more). I would now like to change the size of the array from 4 to 3. I don't seem to be able to find an option (right clicking on the array) that enables me to do this directly. I don't want to use the "reshape array" icon, because this is not what I want to do. I hope I am clear enough.
Thanks for any help,
regards,
Marc
Solved!
Go to Solution.
Attachments:
Forum array.vi 7 KBHI,
If i have understood your question hope this helps you. If you want to change the size of the array right click on the array element and click Data Operations>Delete Element or if you want to do programmatically delete the particular element.
Attachments:
Forum%20array[1].vi 11 KB -
This VI create a 3D array (2x2x3) from a constant in first time.
In the second time the array is resize to obtain a line more (2x3x3).
Why the resize function mixed the values of 2 2D arrays initials or how to add a line of 0 without destroy the initials values ?
I use Labview 6.02Fr and I am sorry for my english!!
Thank you very much beforehand for your answer.
Warmly,
Alain
Attachments:
resize_3D_array.vi 20 KBHad trouble opening your VI for some reason. It sounds like you should be using the Insert Into Array function.
-
How to programmatically resize vi for different screen resolutions ?
Hi,
I have been struggling with this,How can i built a vi that should run for different screen resolutions (on different pc's).
There are several threads on forum , But i dont find the exact solution for it.
I have already tried with VI properties in the VI but i dont think its working.
Can someone please help me ?
Thanks and regards,
Shivkant PaswanYup it is a pain to use panes, but that is the easiest method I've found which meets my requirements. Learn to use panes and splitters effectively, and then learn their limitations and workaround when you find those limitations. In general LabVIEW should handle multi-resolutions, and resizing better but these are the tools we have today.
Unofficial Forum Rules and Guidelines - Hooovahh - LabVIEW Overlord
If 10 out of 10 experts in any field say something is bad, you should probably take their opinion seriously. -
How do I resize an array of strings in a CIN ?
I've been using a call to NumericArrayResize() to allocate enough memory for numeric arrays, but I now have an array of strings that I need to build in a DLL/CIN and pass back to Labview. Can someone point me to a snippet that will demonstrate how to populate an array of strings with data?
Kindest,
WarrenCheck the follwing example. It may be what you want:
Using a CIN to Create an Array of Strings in LabVIEW
http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&AD517F5DCCAF70228625683A000A570F&cat=2F4F574886553A62862567AC004F032D
Also, check the following example, as it provide an example on how to handle strings.
Code Interface Node (CIN) That Converts a LabVIEW String to a C String, Modifies it, and Returns it as a LabVIEW String
http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&D978409908EA760D8625683A000B6B6E&cat=2F4F574886553A62862567AC004F032D
Regards;
EV
www.vartortech.com -
Programmatically resizing Front Panel does not repaint
I am trying to extend the width of a front panel at run time when a user hits a button. The problem is
that the contents of the newly exposed front panel section are not redrawn. I have to either drag
another window over that section or minimize-maximize it to get it to repaint.
My issue is how can I get the front panel to refresh/repaint, or if that is not possible what other
ways are there to do resizing. I have tried changing the "Window Bounds" and "Panel Bounds" properties of
the VI (not at the same time) as well as using LVWUtil32 (Windows API Function Utilities (32-bit) for
LabVIEW). Each of these methods results in the same problem.
Thanks for the help!
NaveenHI Naveen,
It seems to me that you are having Problem with your Graphics Hardware, rather than labview. Generally the window should be repainted by system.
If you go to Display Properties -> Settings -> Advanced -> Troubleshooting or Graphic Acceleration - You may see the slider to full Acceleration. Under this setting the OS basically relegates most graphic duties to Graphic Hardware.
What you may want to do is to Move the slider a couple of notches back. And then try your VI's. Infact try all the settings on your Slider. See if it works at No Acceleration.
The Problem for me is I do not Have this Problem and cannot even simulate it to try a solution.
Another Solution is this -
There is a vi Property Class called "Front Panel" Which can be access
ed from Vi Server. Under this Class you will see a Property "Defer Front Panel Update" Generally this Property is used to Prevent a redraw. But if this Property is set to False, Labview immediately redraws the Panel.
What you may want to do is after resizing to let you program go through this Property Node set to False and See if this Helps.
By The way, the way you have to wire this Property is to Open a Vi Ref, Wire it to Property Node, Select Property as "Front Panel". Right Click on "Front Panel" and Click on Create-> Property -> Defer Front Panel Update. Wire the Referneces of the these Objects, with the output of "Front Panel" going to "Defer FP Update".
I hope your ver of Labview has these Properties. I am Using 6.1
I hope you can take it from there!!
Please advise How you solved the Problem. Good Luck!!
Mache
Another Solution which you can try is this
Good Luck!
Mache -
JFrame flicker on programmatic resize.
Here is the code:
package ui.components;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class Test {
public Test()
final JFrame frame = new JFrame();
frame.setBounds(100, 100, 300, 300);
frame.setBackground(Color.blue);
JPanel panel = new JPanel(new BorderLayout());
JPanel up = new JPanel(new BorderLayout());
up.setPreferredSize(new Dimension(100, 100));
up.setBackground(Color.blue);
JButton button = new JButton("add size/shrink size");
button.addActionListener(
new ActionListener() {
boolean addf = true;
public void actionPerformed(ActionEvent e)
if (addf) {
frame.setSize(
frame.getWidth(),
frame.getHeight() + 50
} else {
frame.setSize(
frame.getWidth(),
frame.getHeight() - 50
addf = !addf;
up.add(button, BorderLayout.CENTER);
JPanel bp = new JPanel();
bp.setBackground(Color.red);
bp.setPreferredSize(new Dimension(100, 200));
panel.add(up, BorderLayout.CENTER);
panel.add(bp, BorderLayout.SOUTH);
frame.setContentPane(panel);
SwingUtilities.invokeLater(
new Runnable() {
public void run()
frame.setVisible(true);
public static void main(String[] args)
new Test();
}Why the frame flickers when the button is pressed ?
I see that JFrame is filled with it's background color.
I know that "sun.awt.noerasebackground" property can be changed to fix that, but I don't want to change any global settings as the effect applies only to one frame.
Thank you.Research "Double Buffering". This will not be a one liner but it will solve your problem.
-
Programmatically resize desktop
I have an anoying problem. My graphincs card is $#!£. Everythime I restart my work laptop I have to reset the screen resolution settings.
Does anyone know:
1) How to Set the display resolution of Windows thriugh LabVIEW?
2) How to select the output device (Monitor, laptop, Laptop & monitor)?
3) How to detect the output device?
I need a better machine, I can't have one, so I need to create a VI to make my life easier.
Cheers
JamesHi James W,
Thank you for contacting National Instruments. Regarding your query, I think you're going to need to look at the Windows API for most of the details on how to do what you want to do. So far, I have found the following details:
1. There is a registry Key that stores the screen resolution, it is located here
HKEY_CURRENT_CONFIG>>System>>CurrentControlSet>>Control>>Video and then drill down from here (I think the large hex value changes between machines).
I can't recommend changing your registry without first backing everything up. You can use the registry VIs within LabVIEW to make this change.
2. I am not sure, I think you will probably need to call some part of the Windows API. I would recommend having a look at MSDN to track this one down.
3. Again, I am not sure. Once you have found the corresponding DLL/Registry Key, you will be able to call them and access them through LabVIEW.
I hope this helps,
Many thanks,
Message Edited by Andrew McL on 04-19-2010 05:06 AM
Andrew McLennan
Applications Engineer
National Instruments -
Having trouble printing an array of prime numbers that has been resized
HI, im having trouble with my printPrimeNumbers() method printing the current state of an array, I can only get it to print the original state it was in. The array is inside of a primeNumbers object. I used checkAndResize to resize that array. my printPrimeNumbers method must be void without a parameter. How could i get my PrintPrimeNumbers method to print out a resized array without modifying the parameter? Any ideas.
Here is my PrimeNumbers class:
* Created by IntelliJ IDEA.
* User: Kevin
* Date: Mar 4, 2007
* Time: 1:53:56 AM
* To change this template use File | Settings | File Templates.
package primes;
public class PrimeNumbers {
private boolean [] sieve;
public PrimeNumbers(int upper) {
initializeSieve(upper);
public int getNthPrime (int n){
int prime = 0;
double num;
if (n >= sieve.length)
checkAndResize(n + 1);
for (int i = 0; i < sieve.length; i++){
if(sieve)
prime++;
if (prime == n)
return i;
if (prime < n && i == sieve.length -1)
checkAndResize(2*sieve.length);
return -1;
public int getNumberPrimeNumbers(int n){
int primes = 0;
for (int i =0 ; i < sieve.length ; i ++){
if (n > sieve.length){
checkAndResize(n);
if(sieve[i])
primes++;
else if (sieve[i])
primes++;
return primes;
public int getSieveSize ()
return sieve.length;
public boolean isPrime (int n) {
if (n > sieve.length){
checkAndResize(n);
//initializeSieve(n);
return sieve[n];
// prints out the prime numbers inside sieve
public void printPrimeNumbers() {
int n = 0;
boolean first = true;
System.out.print("[");
for(int i = 0; i < sieve.length - 1; i++){
n++;
if(sieve[i] == true && n != sieve.length - 1) {
if(first) first = false;
else System.out.print(" ");
System.out.print(i);
System.out.println("]");
// checks length of sieve with N and then resizes sieve if nessecary.
private void checkAndResize (int n){
if ((n + 1) >= sieve.length){
initializeSieve(2*n);
private void setMultiples (int k) {
for (int i = 2*k; i < sieve.length; i += k)
sieve [i] = false;
private void initializeSieve (int upper){
if ( upper < 2)
sieve = new boolean [2];
else
sieve = new boolean [upper + 1];
sieve[0] = false;
sieve[1] = false;
for (int i =2 ; i< sieve.length; i ++ )
sieve[i] = true;
int bound = (int) Math.ceil(Math.sqrt(sieve.length));
for (int i = 2 ; i < bound ; i ++)
if (sieve[i])
setMultiples (i);
private String booleanToString (boolean value)
if (value)
return "T";
else
return "F";
public String toString (){
StringBuffer buf = new StringBuffer("[");
for (int i = 0; i < sieve.length -1 ; i ++)
buf.append(booleanToString (sieve[i]) + " " );
buf.append(booleanToString (sieve[sieve.length -1]) + "]");
return buf.toString();
here is the client code
PrimeNumbers test = new PrimeNumbers(16);
System.out.println(test);
System.out.println("There are " + test.getNumberPrimeNumbers(16) +
" prime nummbers in the sieve from 1 to 15. \n");
System.out.println("There are " + test.getNumberPrimeNumbers(26) +
" prime numbers in the resized sieve from 1 to 25.");
System.out.println("\nThe first 25 prime numbers are:");// makes sense why it doesnt work
test.printPrimeNumbers();
System.out.println("\nThe 13th prime number is: " + test.getNthPrime(13));
System.out.println();
System.out.println("The number 3001 is prime: " + test.isPrime(3001));do you see how my methods resized it?
here is the output:
[F F T T F T F T F F F T F T F F F]
There are 6 prime nummbers in the sieve from 1 to 15.
There are 15 prime numbers in the resized sieve from 1 to 25.
The first 25 prime numbers are:
[2 3 5 7 11 13 17 19 23 29 31 37 41 43 47]// this is only the first 15 elements
The 13th prime number is: 41
The number 3001 is prime: true
thanks for taking your time to look at thisWhat's the problem?
You say that there are 15 prime numbers in the range 1-25. Your method printPrimeNumbers() prints the last calculated primes, and that is 15. So the program works.
Maybe you are looking for
-
We have just purchased a new home computer and need to set up I-Tunes for everyone in our family. Is that possible to do on one computer?
-
My illustrator CS6 crashes when i try to open an AI file with RGB color mode
My illustrator CS6 crashes when i try to open an AI file with RGB color mode. I worked on this file yesterday and changed it to RGB mode. Today i tried to open the file again but illustrator won't open it and crashes. It does work when i want to open
-
Border around Artwork in Cover Flow, iOS 4.3
First of all: please excuse me for my english; it's not my native language. After updating to iOS 4.3 (Mac OS X 10.6.6; iTunes 10.4), I had some problem with some artworks, so I removed and added all my music to my iPhone 4. Suddenly, all the artwork
-
Hi, I have already tracing mechanism that is developed in Java and has a jar for it. Is it possible to use those jars in flex other writing the ActionScripts similar to that Java code? I know that its not possible but still Is there any easy way to d
-
How to change contrast on ipad
please can you tell me how to change the contrast on my ipad