C equivalent code to Matlab's all and any function?

R

renaysingh

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
.............................................................................................................

Thanks

RS
 
T

Tom St Denis

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?

This is a O(n) problem, a for loop and an array will solve it.

SHAZAM!

Tom
 
T

Tom St Denis

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?

This is a O(n) problem, a for loop and an array will solve it.

SHAZAM!

Tom
 
S

Simon Biber

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) return true;
}
return false;
}

bool all(size_t n, bool array[])
{
for(size_t i = 0; i < n; i++)
{
if(!array) return false;
}
return true;
}
 
M

milhous

What is the best way to get Matlab's any and all functions working in
C? [That is without calling Matlab from C]

You can call any c program through SciLab, which is an open source
version of Matlab. Scilab is free and has the same computing
capabilities as Matlab
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top