Jump to content

Update or append array data at arbitrary index?


WMassey

Recommended Posts

It could be done by reference like this example.

Yes, I even considered that once as well. But that, like everything else I have thought of so far, is not a one-box-contains-everything solution. You still need at least one additional external step (in this case, pulling out the array reference) before calling the subVI. If I'm willing to allow one additional external step then I can easily do it very simply with variants. I just thought that, since this seemed like such an obvious thing to routinely do, there should be some universally-polymorphic LabVIEW primative to do it.

Followup:

OK, I'm going to have to retract those last two sentences. It's not so easy with variants. I tried it here:

post-2800-1131061070.png?width=400

and anytime the initial array size value isn't large enough to include the "Index" value I get an "Error 91 occurred at Variant To Data - The data type of the variant is not compatible with the data type wired to the type input."

Link to comment
One way to simplify your code would be to use the reshape array function. See attached image. You still need to check if the index goes beyond the original array size but this method is more efficient.

Hey, that is better! :thumbup:

Thanks!

P.S. I've attached a polymorphic (for the common data types) version of this VI. It still won't do arbitrary cluster data, but it is easy enough to paste TypDef'd controls into its front panel to generate new VI's to handle those data types. I'm just really surprised that this isn't built in by NI somewhere.

Download File:post-2800-1131058454.zip

Link to comment
built in by NI somewhere.

It is sort of: See attached vi for a completly polymorphic version

that can easily be expaned to multi-dimensional arrays.

Uses a reference to the array's element.

But indexing is clumsy, so maybe room for improvment.

Interesting problem. I've never had a use for this operation before.

I can usally make an array with the maximum expected elements first.

-WDC

Download File:post-2910-1131208048.llb

Link to comment
It is sort of: See attached vi for a completly polymorphic version

that can easily be expaned to multi-dimensional arrays.

Uses a reference to the array's element.

But indexing is clumsy, so maybe room for improvment.

Interesting problem. I've never had a use for this operation before.

I can usally make an array with the maximum expected elements first.

-WDC

Wow, interesting approach, though somewhat out of left field. I'm now sure how efficient it would be or is there is a way to make it work without the upper-level VI having a control/indicator for it to operate on but I'll give you points for creativity.

I find I use this operation most often when dealing with instrument/system configuration data that a user is saving to a file devoted to storage of similar data. I have no idea at the outset how many various setups a user might eventually use or want to keep so I have to allow it to dynamically grow. In some cases there is even an advantage to letting the user pick the index which the setting is saved under. I just learned early on that the "insert into array" primitive didn't behave like I thought it should if it was given an index a bit beyond the bounds of the incoming array. Heck, it didn't even return an error.

Thanks for the reply. It was interesting.

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.