re********@gmail.com wrote:

Hi

I am new to C programming.

What is the best way to get Matlab's any and all functions working in

C? [That is without calling Matlab from C]

Is there a library available? Which is the best for speed?

For reference the Matlab help has the following for the all and any

functions:

.................................................. .................................................. .........

Given

A = [0.53 0.67 0.01 0.38 0.07 0.42 0.69]

then B = (A < 0.5) returns logical 1 (true) only where A is less than

one half:

0 0 1 1 1 1 0

The any function reduces such a vector of logical conditions to a

single condition. In this case, any(B) yields logical 1

.................................................. .................................................. .........

From the descriptions of these two functions, you can write the

functions yourself. They take the number of items in the vector and a

pointer to the first element of the vector.

#include <stdbool.h// for bool, true, false

#include <stddef.h // for size_t

bool any(size_t n, bool array[])

{

for(size_t i = 0; i < n; i++)

{

if(array[i]) return true;

}

return false;

}

bool all(size_t n, bool array[])

{

for(size_t i = 0; i < n; i++)

{

if(!array[i]) return false;

}

return true;

}

--

Simon.