# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## How to write an array and a scalar to file?

I would like to write my data to a file but am having trouble approaching the problem. In the file I would like to write both the x and y values of my data points in two columns, however, the y data is in an array and the x data is made up of 3 pieces of information: an initial x, an x incremented value, and the number of points in my data sample. How could I go about this?

Message 1 of 6
(2,817 Views)

## Re: How to write an array and a scalar to file?

Would it be best to create an array of the x values by

[x, x+delta_x, x+ 2delta_x ..... , x+(n-1)delta_x]

where n= to the number of dimensions in the array

and then build a two dimensional array of both the x and y values?

Message 2 of 6
(2,812 Views)

## Re: How to write an array and a scalar to file?

Hello

you could do the way you suggested.

Use a For loop, connect your 'number of samples' to N count, build an array [of x+(n-1)delta_x]. Use 'i' iteration number as your (n-1)

Build a 2D array, of x array and y array.

Then, if you are writing to a spreasheet file, wire the 2D array directly. If you are writing to a text file, use the Array to Spreasheet string and write to the text file

Edit: Note that n is not the number of dimensions, its number of elements in a 1D array

Regards
Freelance_LV
TestAutomation Consultant
Message 3 of 6
(2,797 Views)

## Re: How to write an array and a scalar to file?

@Freelance_LV wrote:

Hello

you could do the way you suggested.

Use a For loop, connect your 'number of samples' to N count, build an array [of x+(n-1)delta_x]. Use 'i' iteration number as your (n-1)

Another option for this is to use the ramp pattern.vi which will do it for you and eliminate the need for you to code up the incrementing inside a for loop

Message 4 of 6
(2,792 Views)
Solution
Accepted by topic author MIMaracuya

## Re: How to write an array and a scalar to file?

The number of points is redundant, because it will be the same as the "other" array.

Here's what I usually do:

Message 5 of 6
(2,791 Views)

## Re: How to write an array and a scalar to file?

Thanks everyone, it's looking great now!

Message 6 of 6
(2,762 Views)