08-19-2023 03:35 PM
Hi guys
I have some arrays of different lengh that I want to save to files.
So, a simple structure like this
works fine, if the lenghts of arays X and Y ae the same.
If there are not , like here
we'll get only the 2 lines. This is normal, but I would like to get this result
I could do that by inspecting each array length and filling the shortest array with Nan's but I have some clusters of arrays as input and looking for a better alternaive, if any.
Thanks
Solved! Go to Solution.
08-19-2023 05:17 PM - edited 08-19-2023 05:22 PM
A FOR loop will only iterate as many times as the shortest autoindexing input array (or value wired to N). You can pad the shorter array with NaNs before the loop. Do you always know which one is shorter?
You could also build them into a 2D array (which will pad with zeroes) and use array to spreadsheet string.
@nitad54449 wrote:
I could do that by inspecting each array length and filling the shortest array with Nan's but I have some clusters of arrays as input and looking for a better alternaive,
If you have more complicated data structures, please show them as example. (... and please attach your VI containing typical default data instead of just pictures!)
08-19-2023 06:01 PM
Hi Christian
Thanks for your input. I have an AE for saving data the way I want... I send commands to create files, send clusters of arrays to save, text or time, then close the file.
For the program I am working on, I want specifically to save Nan to indicate that the data is not available (I don' want 0, as 0 can be a measurement data).
Typically the first array in the cluster is the biggest one.
Regards
08-19-2023 07:22 PM - edited 08-19-2023 07:24 PM
Here's what I might do for all the various cluster save operations (example for cluster of four 1D arrays, but easy to expand). It does not matter which cluster elements has the most elements.
08-19-2023 08:30 PM
thanks,
much better..
didn't know the +Nan thing, but it's logic though.. if you add a number witth a non-number.. what do you get ?
thanks again, Sir 🙂
N
08-20-2023 01:40 AM - edited 08-20-2023 01:41 AM
nvm I'm late with my solution.
08-20-2023 10:35 AM
Note that my code is focused on simplicity and lean code. Other more literal "solutions" would involve measuring the length of each 1D array and find the max, then initialze a 2D array of NaNs or calculate how many NaNs needed to be appended to each 1D array. My solution does not need anything blue or any convoluted code, not even a FOR loop. 😄
More complicated code always has more places for potential bugs to hide. 😄
08-20-2023 11:19 AM
Hi
Thanks, I got it. it work ok !
N