LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to use the min() function on a vector of acquired data in a MathScript Node?

hey there,

 

I'm using Labview to program a colour sensor.

In Labview some computations have to be made to calculate the colour detected closest to the calibration data.

Within a MathScript Node the external data acquired should be processed to find the minimum of 3 values - all of them having a data type of "DBL", so doubles.

No matter if I use the min(vector) function or then do the comparison through if-loops (as there are only 3 variables) like x > y, I always get the same error message: "This function is not defined for non-matrix data types."

Although, the syntax in MathScript should be similar to Matlab.

 

Does anybody know how to circumvent this problem?

 

Thank you in advance!

cheers, matthia

 

configuration: LabVIEW 8.5.1 on Windows XP

Message Edited by mtruess on 05-19-2009 04:27 AM
0 Kudos
Message 1 of 5
(2,725 Views)

hey, it's me again..

 

I am trying to provide some more information on my problem with calling the min() function with variables.

 

the lines within the mathscript node look like the following (signal and count are inputs to this node):

 

if count == 0

   D_r = signal

end

if count == 1

   D_g = signal

end

if count ==2

   D_b = signal

end

 

vector = [D_r D_g D_b];

colour = min(vector);

 

see also the VI attached at the bottom.

 

but this last line will be answered by the already mentioned error message..

it seems like the mathscript node cannot treat variables..

 

still, I hope somebody has the solution to this problem ready..! :smileyhappy:

 

greets,

matthias

 

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

Hi mtruess,

 

try to instantiate your variables outside of the IF statement instead of using the variable for the first time inside the if statement...

 

hope this will solve your problem.

 

cheggers

Sascha
0 Kudos
Message 3 of 5
(2,692 Views)

Hi mtruess,

 

were you able to solve the problem?

 

greetings,

cheggers

Sascha
0 Kudos
Message 4 of 5
(2,659 Views)

Hi Matthias,

 

I'm not able to look at your vi right now, but the given code fragment can be done in LabView using a "Replace array element" function: wire the (old) vector to the input, signal to element, count to index input. At the output you get the "vector" with replaced element which you can wire to the "array min/max" function. Just two primitive functions.

 

If all the other mathscript code is of same quality you should code it all in LabView... 

Best regards,
GerdW


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