By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,084 Members | 1,969 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,084 IT Pros & Developers. It's quick & easy.

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

P: n/a
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

Sep 21 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

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?
This is a O(n) problem, a for loop and an array will solve it.

SHAZAM!

Tom

Sep 21 '06 #2

P: n/a

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?
This is a O(n) problem, a for loop and an array will solve it.

SHAZAM!

Tom

Sep 21 '06 #3

P: n/a
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.
Sep 21 '06 #4

P: n/a
>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

Sep 22 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.