SCL get biggest value from array

vib

Member
Join Date
May 2022
Location
spain
Posts
7
Hello I wanna know if are some function to check what is the max value from an array
or if I have to loop the array to compare all numbers to get the biggest one

Thanks
 
Any function will internally compare the numbers, so you might as well just do the compare yourself.

Start by initialising your max_value variable to the minimum value for your datatype e.g. INT16 = -32768

Code:
max_value := -32768;
FOR i := [I]LowerBound [/I]TO [I]UpperBound [/I]BY 1 DO
  IF arr[i] > max_value THEN
     max_value := arr[i];
  END_IF;
END_FOR;
 
Start by initialising your max_value variable to the minimum value for your datatype e.g. INT16 = -32768
Just copy the 1st element for the initial max value

Code:
max_value := arr[[I]LowerBound[/I]]
FOR i := [I]LowerBound+1[/I] TO [I]UpperBound [/I]BY 1 DO
  IF arr[i] > max_value THEN
     max_value := arr[i];
  END_IF;
END_FOR;
 
Thanks,
then you always have to do the loop

It is the same to SUM two different arrays with the same length?

If I have
A : ARRAY [1..100, 1..100] OF INT ;
B : ARRAY [1..100, 1..100] OF INT ;
Can I do:

A + B ? or I have to loop every position?
 
or I have to loop every position?


You have to (double) loop.

Hoping for SCL/ST syntax to be array-aware is a bit much, don't you think? This isn't Python [summax = max(A+B) # with the numpy module] or a real, extendable language, although you should be able to at least abstract it away to a function.
 

Similar Topics

HI i would like to know how to get a variable that will store the amount of times a program has been executed. The issue is I have 3 DBs for 1 FB...
Replies
2
Views
82
Hi, I have an intermediate-advance knowledge of programming with TIA Porta in Ladder, would you recommend me to start learning SCL for it to...
Replies
11
Views
565
Hello nice to meet you, im new in here, I'm currently trying to convert code written in STL for a S7-400 to SCL for an S7-1500, because when i run...
Replies
5
Views
320
Hi everyone, I am new to this amazing world of PLC, well... I mean, in practice, since I already knew electronics, programming languages, IT, and...
Replies
7
Views
656
Hi all, This is my first post; I am new to PLC Controls stuff and English is not my native language, so I apologize in advance if something is...
Replies
4
Views
514
Back
Top Bottom