trayres Posted March 22, 2011 Report Share Posted March 22, 2011 (edited) 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 March 22, 2011 by trayres Quote Link to comment
hooovahh Posted March 22, 2011 Report Share Posted March 22, 2011 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. 1 Quote Link to comment
Darren Posted March 22, 2011 Report Share Posted March 22, 2011 And if you're looking to use the complex numeric data type instead of keeping the real/imaginary components separate, then use a Re/Im To Complex function instead of a Build Array in hooovahh's instructions above. -D 1 Quote Link to comment
trayres Posted March 22, 2011 Author Report Share Posted March 22, 2011 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! Quote Link to comment
crelf Posted March 23, 2011 Report Share Posted March 23, 2011 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 Quote Link to comment
hooovahh Posted March 23, 2011 Report Share Posted March 23, 2011 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. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.