473,378 Members | 1,555 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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

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
4 3391

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

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
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
>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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: TogaKangaroo | last post by:
A question I'm sure has come up before, but does anyone know how to write/where to find the std for the equivalent of the normalpdf(X, mu, sigma) function in matlab? For anyone who does not know...
1
by: Stef Mientki | last post by:
Does anyone know the equivalent of the MatLab "diff" function. The "diff" functions calculates the difference between 2 succeeding elements of an array. I need to detect (fast) the falling edge of...
6
by: openopt | last post by:
Thank you in advance for your response. Dmitrey
3
by: dmitrey | last post by:
Thank you in advance, Dmitrey
2
by: zipls | last post by:
suppose a simple matlab function //add.m function result=add(left,right) result=left + right; //end of add.m use matlab comtool to encapsulate the function in fun.dll and then use it in...
1
by: santus | last post by:
Hello, I've just join this forum and i need help about using matlab function from .net. I need to make a program to plot data into 2D graphics and the program use use mathematics functions. ...
3
by: prads | last post by:
Hello, I want to write the following matlab code lines in C++. Somebody pls help me... and one more basic question.....what is C++ equivalent of matlab fid...is it rawsignal in:...
4
by: itcecsa | last post by:
Hi, I am implementing a small Python project, what I am going to do is to open Matlab and run some M-files, and get some output from Matlab command prompt. I have no idea how to open Matlab...
1
by: sanctus | last post by:
I have a Matlab code which works fine in windows. Now I installed Xubuntu (because this way I have admin rights(=root) which I don't have on windows) and want to use the same code. To be able to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.