LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I scale 1D array within a range

Solved!
Go to solution

Hello All,

 

I’m facing a hurdle in solving a problem. Probably you can help me.

 

I’m doing scaling my 1D array data to "0". Scaling is working fine but now I’m trying to scale data by a range. I tried like this (I put Input and output as a dummy control so you can leave it):

 

Code-Problem.png

 

The problem happening here, after scaling within the range graph is showing an edge in the end. Please see the attachment (Before and after scaling)

 

Before Scalling.pngAfter Scalling.png

 

Will be great if you tell me where I’m messed up.

 

Thanks,

- Reduanul

0 Kudos
Message 1 of 7
(2,881 Views)

Hi REDUANUL,

 


@REDUANUL wrote:

I’m trying to scale data by a range. I tried like this (I put Input and output as a dummy control so you can leave it):

 

Code-Problem.png

 

The problem happening here, after scaling within the range graph is showing an edge in the end.


  • You do some scaling to the Y data of your plots.
  • But the X data are handled quite differently: you are coercing them! (Did you read the help or atleast the name of that function you use? It's called "InRangeAndCoerce"!) Why do you expect some "scaling" when you "coerce" the values?

 

The plot you get from your VI is totally correct (as you programmed it)!

 

Btw. it would help you and us when you would use the AutoCleanup tool before attaching snippets…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 7
(2,838 Views)

@REDUANUL wrote:

I’m doing scaling my 1D array data to "0".


 

As a first step, you need to explain what scaling data to "0" actually means. Scaling is typically a multiplication. Are you talking about an offset or range? I assume you just want a linear transform of the two Y values. Seems trivial.

 

  • Why are you using a property node instead of wiring to a graph terminal? Why is there no graph terminal?
  • Why is there no data in the diagram constant?
  • are you aware that index array is resizable?
  • What's the purpose of the in range function?
  • For the first plot, you are just subtracting the max. That's shifting, not scaling.
  • For the second plot, you are subtracting the min value, then dividing by the range.
  • You show some graph images, but it is not clear what we should be looking at.
0 Kudos
Message 3 of 7
(2,832 Views)

@ altenbach,

 

Actually, that was my effort. I'm not saying I was correct.

 

I have an XY graph and wanted to scale the Y-axis value to "0" then there should be another thing that I have to do which is Scaling this value (Y-axis data) within a range (i.e from 100 to 500 whereas array value is 10 to 5000).

 

Is there any way to do it?

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

Hello GerdW,

 

"You do some scaling to the Y data of your plots."

 

- Yes I want to do scaling my XY plot data to "0" then I want to choose a range for scaling (for Y-axis data).

 

I got it using "InRangeAndCoerce" was a wrong step!

 

0 Kudos
Message 5 of 7
(2,800 Views)
Solution
Accepted by topic author REDUANUL

Hi Reduanul,

 


@REDUANUL wrote:

which is Scaling this value (Y-axis data) within a range (i.e from 100 to 500 whereas array value is 10 to 5000).

Is there any way to do it?


Ever heard of simple basic math?

z = (y - y_min)/(y_max - y_min) * (range_max - range_min) + range_min
with
y_min, y_max         = [ 10, 5000]
range_min, range_max = [100, 500]

This is basic linear algebra…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 6 of 7
(2,799 Views)

Sometimes you can even forget all the math details and use the built-in tools that LabVIEW offers. (For example linear fit and linear evaluation). You would  use what you have (data min&max) and what you want (limits A&B) as inputs.

In this simple example, the red data is independent of the amplitude and offset inputs used to generate the white data. (unless you have some pathological edge case, e.g. an amplitude of zero.

 

altenbach_0-1626188085111.png

 

Message 7 of 7
(2,764 Views)