473,569 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3418

re********@gmai l.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********@gmai l.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********@gmai l.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
3823
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 what that is it is the equivalent of finding the probability of X in a normal distribution with mean mu and standard deviation sigma?
1
5872
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 a binary signal. There's derivate function in Python diff, but when you use an binary (true/false) input, it also detects rising edges. ...
6
12392
by: openopt | last post by:
Thank you in advance for your response. Dmitrey
3
2911
by: dmitrey | last post by:
Thank you in advance, Dmitrey
2
5303
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 c#.net
1
1998
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. Some friends, suggest me to use matlab but i have never use it before. Is it possible to use matlab function like function for interpolation or...
3
2141
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: file_op.getline(rawsignal,blksize); Thanks, Prads <code> 1) fseek(fid,5,'bof');
4
13726
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 from Python! Any suggestions would be appriciated!
1
4607
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 use the C-code you have to compile it from Matlab comand line with the comand mex myfile.c where before with mex -setup you define which compiler to...
0
7695
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7612
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7922
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8119
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6281
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5509
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5218
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3653
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
936
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.