LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

save 2D array to text file and read it

Your major issue is that you are closing the file reference before trying to get the file path from it.  You can easily fix this by wiring the file path from the close file primitive output to your read from spreadsheet file VI.

 

The reason your data points are not evenly spaced is that you are controlling the timing by the timing of your WHILE loop.  This will depend on how fast your computer can complete the loop and what else is going on at the same time (disk sync, e-mail arrival, etc.).  This could be milliseconds to seconds in variation, but will typically vary around 10ms (dependent on processor and operating system).  You can solve this by switching to continuous samples from your DAQ board, but you will then need to ensure you take data as often as needed to avoid buffer overruns.  This gets us to the next topic.

 

Your data save if very inefficient.  You are saving two points, but going through the motions of saving huge arrays.  It would be far faster to convert the two points explicitly to two strings, concatentate with a tab character between them and EndOfLine at the end, then write that string to the file.

 

If you are writing to disk and not keeping up, you still have a couple of options.  You can use a producer consumer architecture (see LabVIEW help or these forums for lots of examples) to save your data in a separate loop from the data acquisition.  If this does not work, replace your text file format with a binary file, either flat binary or TDMS are fairly easy.  Again, look at the LabVIEW help.

 

Given the large number of flat sequences in your code, you would probably be much better off using a state machine.  Check the LabVIEW help for examples of this.  You may not have time to do it this round, but should learn the pattern for future use.

0 Kudos
Message 11 of 16
(1,964 Views)

Wow, it was a great amout of information and considering I am very new to LabView, so many things you suggested just passed by my ears. 😛 Nevertheless, I am determined to learn it and be efficient in it so I will search the forums and help files as much as possible and try to make sense of all the things you have suggested. 

 

1. about getting the file path, i should connect it before I close it? did I get you right? i will try that and see. 

2. Thank you for explaining the reason for uneven time steps as I was not aware of it. Makes a lot of sense. When you say " It would be far faster to convert the two points explicitly to two strings, concatentate with a tab character between them and EndOfLine at the end, then write that string to the file." honestly, I do not know how to implement that. 😞 

3. Considering the producer consumer atchitecture, I was trying to make sense of it but I did not understand how the two loops were conected to each other as one loop as to finishe in order for other loop to start no? or both loops are running in parellel. After you suggested it I will look into it and try to make further sense of it. 

 

At least you have given me basic ideas how to develope my program further. I really appreciate your time and help. Have a great weekend. 🙂

 

0 Kudos
Message 12 of 16
(1,953 Views)

Here is a simple corrected version.  I made the changes I suggested above.  I also cleaned up the block diagram so most of the wires go left/top to right/bottom.  This makes it easier to read.  I deleted your top level sequence, since it was not doing anything and also deleted the error handler going into the file init for the same reason.  Finally, I did a minor rewrite on the display code to use the index array instead of delete array element.  It should be a bit more efficient.  Hopefully, the file write will be able to keep up with the DAQ.  If not, let us know and we can fix that issue, as well.

0 Kudos
Message 13 of 16
(1,936 Views)

Thank you for your help. Now that I could save data in the text file (see my VI). I have problem importing that into MATLAB. I have two columns of data and when I try to import into matlab, both of the columns are imported into one column. As far as I understood, I think that matlab things the numbers are strings. So if that's the case then do you think that I could change the strings (only the data) to numbers before I save it so that matlab doesn't get confused.

 

Thank you!

0 Kudos
Message 14 of 16
(1,906 Views)

My apologies for the very late reply - I just returned from a family reunion.  I am not familiar with Matlab, but it sounds like you need to find a function similar to LabVIEW's read from spreadsheet file VI.  A generic read will just give you a string, in you case broken up by lines.  If this does not exit, parse each line to get the values and rearrange into a 2D array.  Many moons ago, when I used to use Mathematica extensively, this kind of thing was pretty easy in that package.  If you can't find the function you need, head over to the Mathworks forums and you should be able to get an answer there.

0 Kudos
Message 15 of 16
(1,885 Views)

I figured it out. The problem was that the machine I was running my program was installed in german and instead of dots i had comma. After I changed the settings it all worked fine. Thanks for your help though.

 

@DFGray: hope that you had a good vacation!

0 Kudos
Message 16 of 16
(1,880 Views)