LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Array dimension detection and search/replace

Solved!
Go to solution

Sorry if this is simple, but I can't find an answer and what I've tried doesn't work.

I need to 'invert' and array. By that I mean if an element in an array is zero, make it 255, and if it's 255, make it zero.

That bit is fairly easy, but the array may be 1D or 2D. I can't find a way to detect the dimension. Array size gives a number if the array is 1D and an array if it 2D (or more), but I can't work out how to use this (Doing array size of array size gives an error if the input array is 1D)

Thanks for any help. (Running 8.6 if it makes a difference.)

Message 1 of 9
(2,903 Views)

Might this do what you want to do?

 

regards Florian

0 Kudos
Message 2 of 9
(2,900 Views)

Hi Richard, 

Its not very clear what you are trying to do. Do u just want to replace all 255s with 0 and vice versa in your array? Can you attach the vi which you have so far developed.

 

Regards,


Nitzz 

0 Kudos
Message 3 of 9
(2,893 Views)

Florian,

Thanks, but I missed out the bit about if the original element isn't zero or 255 it should be unchanged. Also, on your vi, if I add a dimension to the input array there's an error. I need to detect the input array dimension automatically.

 

Nitzz,

Yes, all 255 to zero, all zeros's to 255, anything else unchanged, automatically cope with 1 or 2D arrays.

0 Kudos
Message 4 of 9
(2,888 Views)
Solution
Accepted by topic author Richard_M

Richard,

 

if get you correctly the only problem is that you can't predict the dimension of the array you want to process. How is that array created in the first place? Maybe there's a way of keeping track of the dimension right from the creation. Im only guessing of course, maybe it's time you show us a piece of code.

 

regards Florian

0 Kudos
Message 5 of 9
(2,881 Views)

Florian,

The only code I've got got doesn't work, and just looks at the size of the array, then the size of the (size of the array), but this fails when the original array changes from 1D to 2D.

I think you're right about keeping track of the array in the first place, the array is actually the pixel data from a bmp. I can look at the header details which tell me how big the image is.

It just seems hard to find how many dimensions an array has.

 

Thanks for your help,

Richard 

0 Kudos
Message 6 of 9
(2,873 Views)

Hi Richard,

Can you explain how does the dimension of your array change automatically. I mean, the array control must be connected to some functions. How can it automatially change its dimension? Hope you wont mind my asking this. Just wanted to get a better picture of your problem.

 

Regards,

Nitzz 

0 Kudos
Message 7 of 9
(2,871 Views)

You should use 2D for everthing. If it's "1D" it'll be only one column in a 2D array. Try to change the size of the array with the controller.

Regards,
Even
_________________________________
Certified LabVIEW Associate Developer

Automated Test Developer
Topro AS
Norway
0 Kudos
Message 8 of 9
(2,867 Views)

The array is the image data of a bmp file. It can be a single row of pixels, a 1D array, or a number of rows, a 2D array. I need to do some processing on this array, so I need to know whether it's 1 or 2D. But as mentioned above, I should be able to read the bmp file header to get this info, then use either a 1 or 2D version of the actual conversion bit.

 

Even,

My first attempt was to use 'size of array' which is fine but only outputs a number if the array is 1d, this is enough for any thing I could come up with to fail.

Thanks again,

Richard

0 Kudos
Message 9 of 9
(2,862 Views)