LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

reorganize a 2D array

Hi dear all:
 
I have a question about reorganization a 2D array.
 
If I have a 2D array, for example:
 
101  80  1
101  79  2
101  81  3
101  95  4
102  88  1
102  79  2
102  85  4
103  75  1
103  76  3
103  79  4
 
How can I reorganize that to a 2D array as:
 
80  88  75
79  79  0
81  0    76
95  85  79
 
I can take them apart in order for sure, but I just don't understand how to add 0 into it if there is no data.
Please give me some advice.
 
Dave
 
 
0 Kudos
Message 1 of 10
(3,127 Views)
I am not sure how you know when there is no data, but apparently you do.

What I would do in such a case is initialize the output array with all 0 elements and then use the Replace Array Element function to put the reorganized data into the appropriate elements. This will leave a zero in any unchanged element. If zero can ever be a valid data value, NaN (Not a Number) might be a better choice for the misssing data.

Lynn
Message 2 of 10
(3,121 Views)
Try something like in the attached VI (LabVIEW 7.0).

Message Edited by altenbach on 02-21-2006 08:40 AM

Message 3 of 10
(3,122 Views)

Lynn:

Well, my source is a CSV file that's how I know there is no data. This is just a part of my VI and I have to read the array after reorganization by some kind of indicators and that's why I choose zero instead of N/A. Thank you for your reply.

 
Altenbach:

Thanks for your VI. I am looking into it right now.

Dave

 

0 Kudos
Message 4 of 10
(3,097 Views)

Hey, would you interest in a second round 2D array recoganization ?

101,79.0,2005-11-01 03:15:00
101,79.0,2005-11-01 03:30:00
                      ...
                      ...
                      ...                   
108,71.0,2005-12-16 11:00:00
108,71.0,2005-12-16 11:15:00
201,83.0,2005-11-01 01:30:00
201,83.0,2005-11-01 04:00:00
                      ...
                      ...
                      ...
903,82.0,2005-12-16 12:00:00
903,81.0,2005-12-16 12:15:00     

This is a fractional of the CSV file I was talking about. And my question is "how can I convert the data&time into something I can use?" The data was record in every 15mins if there is good communication. It's not as easy as 1,2,3 in the previously message. If I read this CSV file using "Read From Spreadsheet File", the third column will show 2005 only since " - " isn't a number. If I use "Read Characters From File" or  "Read Lines From File", that will end up into a big string. I am thinking to use "Search and Replace String" so I can make the third part as 200512161100 then storm my brain again. I also think of to convert the data and time into seconds but I don't know how to do that.

Can anyone give me any idea ?

Also, in the previous message, I had 101,102 and 103 in the first column. But actually I have 101, 102....108, 201....808,901,902 and 903 in my first column, which is not a continuous set. I am thinking to use a loop to make that set become 0,1,2...67 for further programming use. A while loop will decide how much has to be deducted. For example, 101~108 will be deduct 101 to become 0~7 and 201~209 will be decudt 193 to become 8~16. Is this the only way I can do?   

 

0 Kudos
Message 5 of 10
(3,064 Views)
Dave,

Read the file as a string. Pass the string to Spreadsheet string to array function. Connect a 2D array of strings (it can be an empty array) to the Array Type (2D Dbl) input. Even though that input defaults to Double precision numeric, the input is polymorphic and will accept the string array. The output is then a 2D array of strings. The elements which are pure numbers can be converted to numbers. The elements with date and time strings can be converted to timestamp types or whatever you need. I did not look at the data format to see how involved the conversion will be. It may be tedious, but it is not likely to be too difficult.

Lynn
Message 6 of 10
(3,059 Views)
As Lynn indicated, getting the date/time string into a timestamp can be a bit arduous.  LV8 makes it a little easier with the Scan from String function. 




Message Edited by jasonhill on 02-21-2006 05:25 PM

Message 7 of 10
(3,050 Views)


@jasonhill wrote:
LV8 makes it a little easier with the Scan from String function. 

Why 8? This already exists in several older versions.

I wrote the attached VI once for doing these conversions (personally, I believe a VI with this functionality should be an LV primitive). It's not as efficient as the direct conversions, but it does help if you have varying formats. P.S. - I haven't thoroughly tested this VI. It may still have bugs.


___________________
Try to take over the world!
Message 8 of 10
(3,034 Views)
I am an idiot.  I cannot believe I had been using 7.1 for the better part of a year and did not notice that function.  I remember finding it while migrating to 8.0 and thinking "Wow, neat!"

Chalk it up to over-exuberent newbie.
Message 9 of 10
(3,021 Views)

Yes, the Scan From String really works !! I use Read Lines From File and then Scan From String to get time stamp just as Jasonhill showed. With the remaining string and the Feedback Node , I can read through all the lines and put those into a array.

Thank you all !!!!!Smiley Very HappySmiley Very HappySmiley Very Happy

 

0 Kudos
Message 10 of 10
(3,002 Views)