Jump to content

spreadsheet string to 2D array


Recommended Posts

Hi All,

I have a long string of comma separated values in scientific notation being returned from a GPIB instrument. Each 2 values in the string makes up the real and imaginary part of a complex number. I'd like to move this data to an array, where each row then becomes one complex number.

Ex:

10735E-3,-298E-2, 3031E-3.... (made up numbers)

So 10735E-3 would be the real part of the first point, -298E-2 would be the imaginary part of the first point, 3031E-3 would be the real part of the second point, etc, etc. There are 401 points (if that helps)

Could someone point me in the right direction?

Thanks for your time!

-Travis

Edited by trayres
Link to comment

I would use the Spreadsheet String to Array function converting the whole thing to a 1D array using the comma character as a delimiter. I'd then remove white space from each element in the array from the front and back.

This will give you a 1D array, where every even index is real, every odd index is imaginary. Then you can use the Decimate 1D Array function getting a 1D array of real, and 1D array of imaginary. Then you can take these two 1D arrays, and make a 2D array (using Build Array) which will make a 2D array with two columns (or two rows using transpose 2D array). Hope this helps.

  • Like 1
Link to comment

Thank you both greatly!

hooovah - I did not remove the white space in the array, but it appears to work correctly. Is there a subtle reason or bug I must watch for, from whence your suggestion stems?

I went from endless mucking about to your very elegant solution!

Thanks again!

Link to comment
hooovah - I did not remove the white space in the array, but it appears to work correctly. Is there a subtle reason or bug I must watch for, from whence your suggestion stems?

Spreadsheet to string adds a \r\n (sometimes known as CR+LF) characters to the end of the string - I assume hooovahh is refering to those.

I went from endless mucking about to your very elegant solution!

That's the power of LAVA :)

Link to comment

Spreadsheet to string adds a \r\n (sometimes known as CR+LF) characters to the end of the string - I assume hooovahh is refering to those.

That was part of it. The other reason was because if you have something like this as your string

1234, 5678

And then use the Spreadsheet String to Array function using comma character you will have the first element be

1234

And the second element be

\s5678

(Note the space before the 5678), I just recommended the remove white space so that your array is simply the numbers. If farther down the line you wanted to do something with the string representation, say transmit it over RS232, you would transmit the space character then 5678. For your use it may not be necessary.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.