LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to reshape an array using mathscript

Hi guys,

 

I'm creating a program for the evaluation of the dynamic behavior of supercapacitor and to achieve my goal I have a really long array with thousands of point.

To reshape this array I create many submask using the Labview blocks of "reshape array" and so on but to do that for all points is quite a mess. 

The process that I have to follow is this:

Split the main array in subgroups of 100 points, take the mean value of this 100 points and finally create a new array made of mean values.

 

Could you help me to do this with only one mathscript instead of hundreds of submask and stuff like that?

0 Kudos
Message 1 of 7
(2,545 Views)
  • There is no Mathscript anywhere on your diagram, so I don't understand the question.
  • LabVIEW has a "reshape array" function and I don't see that either.
  • You did not attach any of your subVIs.
  • Why do you have all these different subVIs? Don't they all do the same thing?
  • Did you know that "index array" is resizeable?
  • Typically, dataflow should be left-to-right, not in all possible direction. It is hard to understand the program without doing a cleanup first.
  • there is no need for dynamic data and express VIs. XY graphs understand simpler datatypes, e.g. 1D complex arrays.
  • Why do your subVI have such random and unintuitive names?
  • ...

 

Can you reduce your VI to a simple example, then explain what the output should look like?

0 Kudos
Message 2 of 7
(2,524 Views)

You have a 1D array with many points, and want to form a new array consisting of the mean of each set of 100 points.  You can do the entire thing with a few LabVIEW functions and a For loop.

  • Assume your 1D array has N elements.  If you don't know in advance the size of the array, use Array Size to find N.
  • Use Reshape Array to make a new array having 100 columns and N/100 rows.  Both the number of Columns and number of Rows need to be integers -- I'll leave it to you to think about how you want to handle things if N isn't evenly divisible by 100.
  • Now you have a 2D array whose rows are sets of 100 elements of the original Array.  Run this into a For loop, whose indexing Tunnel will give you a row.  Pass this through the Mean function and output the Mean through another indexing Tunnel to give you the desired Array of Means.

You should be able to write this code from the above description.  I hope you do so before someone thoughtlessly posts the code.

 

Bob Schor

0 Kudos
Message 3 of 7
(2,521 Views)

Thank you so much for your reply, I'm going to try to do like you say because i think it's really a good idea! Thanks again for now!

 

Simone Guidi

0 Kudos
Message 4 of 7
(2,519 Views)

Here's a simple VI that does about the same as yours. Arguably simpler. 😄

 

Average100.png

 

 

0 Kudos
Message 5 of 7
(2,517 Views)

@Bob_Schor wrote:

You should be able to write this code from the above description.  I hope you do so before someone thoughtlessly posts the code.

 


I did not see Bob's message, but I don't think my post was thoughtless. It contained sufficiently obscure modifications that will allow you to learn about datatypes and array operations. In fact if you put in some effort to fully understand it, it will put you on a fast track to become a better programmer. You will also appreciate how elegant and powerful LabVIEW is! 😄 Enjoy!

Message 6 of 7
(2,508 Views)

Anything by Altenbach is never thoughtless, but thoughtful.  Not all posters, however, are as knowledgable and generally helpful as he -- as I generally try to do, he also is interesting in teaching  others about LabVIEW, not showing how clever he is.

 

Bob Schor

0 Kudos
Message 7 of 7
(2,489 Views)