LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Obtaining 1 element from a cluster?

Solved!
Go to solution

Hi there,

 

I've attached a piece of code which is attempting to use case statements attached to a slider control to select a specific Torque-RPM array for interpolation. (Interpolation will be done in another VI)

I am a bit of a noobie at LabVIEW and am struggling to obtain a single array as an output. 

Could somebody please help me with this?

 

Any feedback on streamlining this code and improving it would also be massively appreciated.

 

Thanks,

Chango 

0 Kudos
Message 1 of 5
(2,338 Views)

Hi Chango,

 

am struggling to obtain a single array as an output.

Because you are creating a cluster from several arrays. Why do you do that?

 

As you are a noob you should start with simple switch statements:

IF slider = 10
THEN use array10
ELSE
  IF slider=20
  THEN use array20
  ELSE
    if slider=30…

When you mastered that simple concept you will get a better one:

Build a 3D array from your 10 2D-arrays. Then divide the slider value by 10 (to get 1…10) and subtract 1, resulting in a value of 0…9. Use this value to index the right page from your 3D array holding all those mapping parameters…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 5
(2,326 Views)
Solution
Accepted by topic author ChangoMutney

You have 10 12x3 arrays (they are all the same size, the first column is always a constant specific to the Array, the second columns are all identical, and the third column has data that are a function of the first (constant) column and the identical-between-arrays second column.  This suggests a 3D array, 10x12x2, where the first index (0 .. 9) corresponds to %Throttle (index 0 is 10% and index 9 is 100%), the 12 rows correspond to the 12 Throttle settings (all identical), and the 2 columns are RPM and Torque.  You now have a single Array, don't need to do any funny comparisons etc., just need to map your Throttle Position Slider (which gives you 10, 20, ..., 100) into 0 .. 9 (divide by 10 and subtract 1), then use Index Array to give you the corresponding 2D Array of RPM and Torque.  Much less code, much simpler data structure.

 

One other thing -- numeric Controls such as your Slider can be configured to have Text Labels (10, 20, ... 100) and yet directly give you 0 .. 9.   Just for fun, I took your VI, added such a Slider (it's called Throttle Position % 2) that you can examine (right-click and look at its Properties, especially those at the end, and see what I changed).  I also got rid of your Cluster and created from your 10 12x3 Arrays a single 10x12x2 Array (I first deleted Column 0, which is superfluous, then wired all 10 into a Build Array).  Now I wired my Slider into an Index Array, and if you set that Slider to, say, 70, and run the program, you'll get back the RPM and Torque readings corresponding to your 70% Throttle-RPM-Torque Array.  No muss, no fuss, no Cluster.

 

Bob Schor

Message 3 of 5
(2,313 Views)

How stupid I am!  I just posted my clever Single Throttle-RPM-Torque array solution, where I mapped Throttle into the first index to get the 2D RPM vs Torque.  But just as one can map 10% Throttle into First Index 0, one should also be able to map 15000 RPM into Second Index 0, meaning we can convert the 10 x 12 x 2 Array (where the 12 entries of RPM, from 15000 to 4000, are the same for all 10 Throttles) into a 10 x 12 x 1 Array and guess what this simplifies to -- a 10 x 12 2D Array!  I leave that as an Exercise for you -- create a Slider that has labels 15000, 14000, ... 4000 and produces values 0 .. 11 (just as I did for the % Throttle Slider).

 

Bob Schor

Message 4 of 5
(2,312 Views)

Hi Bob,

 

Thanks very much for your reply and showing a better way of doing it.

Muchly appreciated.

 

Chango

0 Kudos
Message 5 of 5
(2,276 Views)