LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

help with Array to spreadsheet string

Solved!
Go to solution

Hi,

I need help to format my 2D array into a string.

I have a DBL 2D array like this:

DBL 2D array.PNG

and I want it in a string format like this "0 0.12, 1 0.34, 2 0.11"

 Row 0 Col 0 <space> Row 0 Col 1 <comma> Row 1 Col 0 <space> Row 1 Col 1 <comma> Row 2 Col 0 <space> Row 2 Col 1 ... and so on

 

Is this doable with "Array to spreadsheet string" function or do I need to use a for loop to format it in this way?

 

Thanks,

Ritesh

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

Array to spreadsheet string cause use space as a delimiter like you want between each column, but will always use End of Line character for the end of each row.

 

You could use a simple nested For loop setup to do what you want.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 14
(7,921 Views)

Here what I would do

format.png

Senior Software Developer
0 Kudos
Message 3 of 14
(7,906 Views)

Sorry for the little bug, here is the corrected version. Notice that inner for loop has a space after %s in "false" case.

format.png

Senior Software Developer
0 Kudos
Message 4 of 14
(7,894 Views)

Well, I made a really simple version. Ignore my nested For loop idea above.

Here's what you want. This just bypasses the 2D aspect and allows you to customize everything as 1D arrays.

Example_VI.png

(Adjust the %#_2f format to match the precision you want. The 2 I used just meeans it will max you out at two decimal places)

 

Freelion, you can clean what you did up a lot by just using the Trim Whitespace node.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 5 of 14
(7,884 Views)

Thanks for your suggestions! I have implemented a "for loop" solution which has less code than the one suggested on this thread. 

 

2DArrayToString.PNG

Let me know if you guys think there is a simpler solution to this problem. I was thinking of using "Array To Spreadsheet String" vi but couldn't get what I want. 

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

Did you se my latest reply? I think that's simpler than what you did. It uses Array to Spreadsheet String, but only for 1D conversion.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 7 of 14
(7,861 Views)
Solution
Accepted by topic author LVCoder

Here are 2 ways to do it without loop.

 

no loop.png

 

Ben64

 

EDIT: just realized you want a comma to separate rows, replace the tab by a comma in solution 1. (solution 2 will not work in this case)

Message 8 of 14
(7,850 Views)

Hi James, it was something I made in 5 min. which gives him what he wants. Does your code have a space after comma? If so, it is not exactly what he asked for.

Senior Software Developer
0 Kudos
Message 9 of 14
(7,844 Views)

@ben64 wrote:

Here are 2 ways to do it without loop.

 

 

Ben64

 

EDIT: just realized you want a comma to separate rows, replace the tab by a comma in solution 1. (solution 2 will not work in this case)


What's up with that funky pattern replace VI? I haven't seen that before. This would be my version:

Example_VI.png

 

Freelion, it does have a space after the comma because that's what his example output had from OP's original post. The space can be removed, or any delimiter can be put in its place.

 

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


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