LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Delete elements in a 2d array

Hi,

 

I'm getting data from a precision thermometer and want to save it in a 2d array. The problem is that the thermometer has a sample rate of approx. 1Hz. This means that I have for each of my 12 channels only one value each 12 seconds. So I'm getting data every single second for a different channel. In the mean while the value is 0. Therefore, my 2d array looks something like in the attachment.

 

Is there a way to delete all the zeros? I've tried using a for loop in combination with the search 1d array function but I couldn't really figure out how to convert it back into a 2d array. Any suggestions?

 

Thanks,

David

 

 

0 Kudos
Message 1 of 14
(7,936 Views)

Hi David,

to use a loop sounds great, but don´t delete in it. Sort out the values you need. I think it should also be possible to do it while record the data. You can store an index for every channel and write the new value by channel and index into an initialized array.

 

Mike

Message Edited by MikeS81 on 11-18-2008 02:18 PM
0 Kudos
Message 2 of 14
(7,921 Views)
"converting back" into the 2d array is done with a shift register. The rest
of your plan sounds like the normal way to do this, altough I'd use a while
loop.

So in short: create a while loop. Put a search array funtion in it. Wire the
array to it, through a shift register (wire the array, then click the
terminal where the array wire enters the while loop, and right click it and
select "create shift register"). If the returned value is -1, stop the loop.
Else, delete the element. Put the array resulting from the delete array back
into the shift register.

You could also set the start index of the array, so LV doesn't have to
search the entire array over and over again. If you deleted element 5, set
5-1 as new start index. Don't put 5 in it, since the entire array is
shrunken, and the new element 5 might be a zero as well!

Someone might do this for you, but I think it's better to try it yourself.
You'll learn more by doing.

Regards,

Wiebe.


0 Kudos
Message 3 of 14
(7,908 Views)

Hi Mike, hi Wiebe, thanks for the quick response.

 

@ Mike: I don't really know what you mean. How am i supposed to store all the indices and then delete the values later? And even if, there is still the problem with converting it back into a 2d array.

 

@ Wiebe: What you described is excactly what i did. The only problem with that solution though is that you cannot wire a 2d array through a shift register and then try to use the search 1d array function. Since I'm only able to search a 1d array I have to use another way to get the zeros out. I was able to so with a for loop. But then I had the problem to convert it back into a 2d array.

 

Is there maybe a way to directly search in a 2d array?

 

Thanks,

David 

0 Kudos
Message 4 of 14
(7,893 Views)
I think your problem lies in how you are creating the 2D array in the first place. If a value is zero, why are you even writing it? Instead of jumping through all of these hoops to correct the data after you've written it, why don't you show how you are writing it so that the problem can be eliminated at the very beginning?
Message 5 of 14
(7,886 Views)
I missed the part about the array being 2d... Kinda stupid, since I actually
repeated it... Didn't look at the picture either.

Mike has a point, you should really try to do this during the creating of
the data...

Anyway, the simple way to do this is exactly like I described, only you need
to put a for loop around it, so the routine works on 1D array's. If you use
auto indexing, you'll automatically get a 2D array as output. If the filter
routine doesn't operate in the right direction, use a transpose 2D array
function before and after the filtering.

This is the simple way to do it, not the most efficient way. If you have
large sets of data, Mike's suggestion becomes more and more attractive. If
that really isn't possible, there are ways to make the filtering much more
efficient. But we can get to that when it's relevant. Never optimize if it's
fast enough (, unless you're bored) .

Regards,

Wiebe.


0 Kudos
Message 6 of 14
(7,877 Views)

Yeah, just give a pic of your block diagram, at least of the loop in question; someone might be able to clean it up for you.  You can just copy your block diagram, or just parts of it (be sure the wires are highlighted too) and paste it in MSpaint, or some other simple paint program.  Or, hit the Print Screen button on your keyboard to copy what you see on your screen, then open up a paint program to paste the image.

 

  But yes, it seems that the way you have constructed your loop(s) is your problem.  So, am I correct in saying that you have 12 channels recording temperature, and once every second a channel records its temp, but the others output zero since you're only recording one at a time? How did you set up the task?  I mean, there should be no reason why you couldn't record all simultaneously, unless you've created separate tasks for each channel?  I am not sure what hardware you have, but I am assuming you can create new NI-DAQmx tasks.  If that's the case, then open up the Measurement and Automation Explorer, right-click on Data Neighbourhood, and select 'Create new...', and select NI-DAQmx Task.  Go through the options... input temperature, etc.  Now add all 12 channels in the same task.  Set the acquisition rate and then numer of samples, and set the mode; all of these options can be specified using property nodes in the program too.  Going to your block diagram, you can place a Task Constant, and select the task you just created in it, and use the other Measurement I/O VIs to read from your hardware.  I have explained all this because I ran into problems before when I neglected to put multiple channels in the same task; there were conflicts because Labview will not allow two or more input, or two+ output tasks to run at the same time (although an input and output task can run side-by-side). 

 

  I hope that helps, and again, send out a pic of your block diagram so someone can perhaps help simplify the task.  

 

 

Cheers,

 

Dan 

0 Kudos
Message 7 of 14
(7,868 Views)

Here is the VI.

 

I'm using instrument drivers for the precision thermometer so I kind of have to take the data how I get it. I tried already first deleting the zeros in the 1d array and then building a 2d array but since the values are slightly shifted each time I won't have the channels in the right order anymore.

0 Kudos
Message 8 of 14
(7,867 Views)

Hey Dan,

 

that's correct. I have 12 channels and each second I get the value of one of these channels. Unfortunately, I am physically restricted by the sample rate of approx. 1Hz. Since the thermometer is a high precision thermometer there is no way of increasing the sample rate. The thermometer is connected through the seriell port of my computer. Hence, I have to take the data how I get it. The only solution I see is to delete these 11 zeros I get every second since I cannot change the way of how I get my data.

0 Kudos
Message 9 of 14
(7,860 Views)

Hi David112,

can you show the DDM1000_DAQ.vi? I think you should delete the zeros there.

 

Mike

0 Kudos
Message 10 of 14
(7,839 Views)