Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Wrong type or wrong number of arguments to Integer

Wrong type or wrong number of arguments to Integer

Always the same error "Wrong type or wrong number of arguments to Integer(vector[i])."

I just want to compare the elements of a Real vector (e.g. [-1, 0, 1, 4]) to an Integer.
But I cannot convert the element of the vector to an Integer! I would avoid to compare Reals!

My code is simple as the following:

Code:


function findElement
    extends Modelica.Icons.Function;
    input Integer e "Search for e2";
    input Real[:] vector "Vector to search";
    output Integer result;
  algorithm
    result := 0;
    for i in 1:size(vector,1) loop
      if Integer(vector[i]) == e then
        result := i;
        break;
      end if;
    end for;
  end findElement;

Re: Wrong type or wrong number of arguments to Integer

Wops, I mispelled the name of the function.
Although many other conversion function start with Capital letter (String(enum), Integer(enum), etc...), the one that translates from Integer to Real is
integer(Real num)
instead of
Integer(Real num)

There are 0 guests and 0 other users also viewing this topic
You are here: