I have an application thats has been coded in C#. After build it generates a standalone dll file and the exe file.
I want to use this code in Matlab. I found out from this page that I can load the C# classes or codes into Matlab.
dll_in_matlab = NET.addAssembly('location to the dll file)
I have the code and the application buty unfortunately I do not understand C# at all. So after using this command I was able to see a .NET object in my workspace and this is what I got for its properties and its classes:
evmaps =
NET.Assembly handle
Package: NET
Properties for class NET.Assembly:
AssemblyHandle
Classes
Structures
Enums
GenericTypes
[code]....
This is the application it produces: [URL] and here is the virustotal result for my application just to ensure that its clean. [URL] .....
I am not a C programmer (or a programmer at all). I am just a hobbyist who writes random code (i.e.: ignorant).C is not my area, and I my experience with it is quite LIMITED!Today, I found out that if I need to get "square root" in C I will be in trouble if I depend solely on the compiler..Is it possible to make the compiler to generate smarter code for this (quite trivial code):
Code:
void intprime_c(unsigned long* fprimes, unsigned long count) { unsigned long divc = 3; unsigned long num = 2; unsigned long sqr; unsigned long pfound = 0; }
[code]...
By "without ugly hacks" I mean using already existing code that came with GCC. Because the others did not need ugly hacks to perform better (it is all about being fair).To compute the "square root" in x86 one just need 3 instructions:
fild fsqrt fistp
But the compiler is generating a call to a "fsqrt" function and wasting a lot of time by doing this. If not, then why is it taking so long? Is it something wrong in my code (at least the output was verified to be the correct)?
Time taken to get the first 2500000 primes (x86_64):
Assembly = 72.400s (human written, unoptimized, coder level: newbie (i.e.: ignorant)) pascal = 75.200s (written by the same person) C (fsqrt) = 83.600s (written by the same person) C (sqrt) = 85.900s (written by the same person)
If it matters, I compiled the C code with this command: gcc -O2 -fno-omit-frame-pointer -fPIC -c ./prime.
I have a struct that I'm writing in C and need to use a mex function to use it in matlab. The struct was originally in matlab and need to have the variables:
force = feval(forcing, Euler, Euler.x(:,k)); q = squeeze(q(:,k,:)/>/>); q0 = squeeze(Euler.q0(:,k,:)/>/>); nx = Euler.nx(:,k);% normal vector J = Euler.J(1,k); rx = Euler.rx(1,k); qh = reshape(qh(k:k+1,:)/>/>,[],1); k = k;
The mex function I have come up with is:
#include "mex.h" /* Extract local info for element k */ /* local struct */ typedef struct { double force; double q;
I have en error translating a function from Matlab to C/C++ :
Code: radius(floor(rows/2+1),floor(cols/2+1)) = 1; % Get rid of the 0 radius value at the 0 % frequency point (now at top-left corner) % so that taking the log of the radius will % not cause trouble.
What I did is:
Code: radius[rows/2][cols/2]=1;
I m sure it s there the problem, because before this line I can print what I want and I can see it at run-time, but after this line I can not print nothing and the work is like blocked. Do you know the error?
I have a class 'A' which is almost perfect for my needs. Class 'B' uses class 'A' I've now designed Class 'C' and Class 'D' and noticed that there is a good chunk of code in class 'B', 'C' and 'D' for using Class 'A' is duplicated. I've separated out this code in specific, standalone functions in each of the classes. Now I'm wondering where this code should go. At the moment, the functions are duplicated in the three calling classes (B, C and D). Placing the functions into class 'A' would break the single responsibility principle. Inheritance to add functionality would likely break both SRP and LSP. The one that seems that it may work is composition.
However, Is designing a complete class just for a few functions over kill?
Would it be valid for classes 'B', 'C' and 'D' to access both the new class 'E' (which would depend on A) and the old class 'A' (which would have to be the same instance as the instance in the new class 'E'), or should the new class 'E' provide sufficient functionality so that Classes B, C and D don't need to access Class A directly? It would seem that its then an incomplete interface of the original object with additional functionality (ie, incompatible) Or should I do it a completely different way?
I'm trying to generate random numbers so that I can assign people to teams. So far I have come up with this
Code:
int generateTeam(){ int i, teamNumber, c, n; for (c = 0; c <= 5; c++) { n = rand()%100 + 1; }
[code]....
}//end generateTeam I'm not sure how to make it so that I can exclude the previous random number when generating the next one. As an example, I have 22 students and I get the number 19. Now I can't have 19 again because that guy already has it.
I am a very very beginner at programming with C. Well, basically i have to generate a real number between 0 and 1 (which as the same as from 0 to 100 k and than dividing everything with 100 k).
Why I am constantly talking about 100 k? Because I would need approx 50 000 random numbers between 0 and 1. My code currently looks something like this:
Code:
int main(int argc, char** argv) { int min,max; double number; srand((unsigned)time(NULL)); number = 1 + rand()%100; printf("The number is: %lf",number); sleep(2); return (EXIT_SUCCESS); }
And If I am not mistaken, should generate numbers between 0 and 100. But I can't figure it out how to change to code in order to get enough numbers.
ID Group 0 2 1 2 2 3 3 4 4 4 5 4 6 4 7 4 Code: I want to store ID values on the bases of same Group, like we do in Hash table (key, value) .
Group ID 2 0,1 3 2 4 3,4,5,6,7
so when i said key 2 it will give me 0,1. how can i do it. As first i thought that i can use array of array but then how i can store the value of key. Now I am thinking of hash but i don't know how I will store and retrieve these values.
I just re-installed my OS some days ago,which contained Visual Studio.But I don't want to use the VS any more(at least in my computer) as the interminable installing process.Then I take Eclipse as my C/C++ IDE by MinGW and CDT. My Java program need to load an DLL file which wrote by C.But when I generating the DLL file,I got some errors.It seems that the compiler cannot find the header files. By the way,I just want to implement the hello-world program in C and invoke it in the Java program.This is my Java testing program:
Code:
public class HelloWorld{ public native void printHelloWorld(); static{ System.loadLibrary("hello"); } public static void main(String[] args){ new HelloWorld().printHelloWorld(); } }
And this is the header file generating by "javah HelloWorld":
Code:
/* DO NOT EDIT THIS FILE - it is machine generated */#include <jni.h>/* Header for class HelloWorld */ #ifndef _Included_HelloWorld #define _Included_HelloWorld #ifdef __cplusplus extern "C" { #endif
I'm trying to write a program that generates a random number between 50 and 200. I made a program that generates random numbers, but how to make those random numbers be in-between 50 and 200. Any example of a program that generates random numbers that are confined in-between certain values?
I know how to generate all permutations of a list like: {'h','e','k','p'}
But I am needing to know how to generate all permutations like: {{'a','b'}, {'h','k','d'}, ..... } such that the first character is either an 'a' or a 'b' and the second character is one of the three in the second list, etc. There will be less than 600 000 permutations.
I am trying to generate two arrays from one big array, of which the sum of the 2 array's elements are as close to equal or equal to each other if possible, or one array summed up minus the second array summed up will be as close to zero as possible. I start with int array of 30.
It says that the lowest possible combination of one array minus the other is 239 which I know is not true. Also this needs to run in under ten minutes.
#include <iostream> using namespace std; const int size = 30;
Given a number "n" supplied by the user, write all the prime numbers less than or equal to "n"
not at all how to make the number I enter me for the numbers that I need even a couple makes the prime number if the command is used repeat for but and decision making but the truth is that I can think of no way to do for this exercise is that the prime numbers are those numbers which are divided only by 1 and themselves also
until the moment I have this code
#include <stdio.h> #include <stdlib.h> main(){ int n; n=0; printf("enter the desired number: "); scanf("%f",&n); system("pause"); }
The program is to generate random numbers to a file and will have one integer parameter, Open a file and then using a loop write the required number of random numbers to the file. Scale the random numbers from 1 and 100 inclusive. Then closes the file .The last function will read the numbers in the file into your program. so far i have
I'm a beginner in C programming and I've got a task that can't finish it..I'm supposed to generate and print the subsets of a group that its size I should enter. Pointers are not allowed!!
so I'm creating a program that generates random sentences with structs..I'm trying to use structs and and create 4 different groupings article, noun, verb, and preposition. Then I'm trying to use "r = rand() % ;" to randomly pick one one word from each group to make a sentence. this is what i have
Code:
typedef enum article { the = 1, a, one, some, any } article; typedef enum noun { boy = 1, girl, dog, town, car }
I want to print different color names for "nb " times . I get the number " nb " from the user or from text file . if " nb = 3 " then I want to print any 3 different color names which means that I may print ( red , green , blue ) for example . and if " nb=5 " then I have to print any five different color names ( pink , blue , black , red ,white ) fore example .
Note : " nb " may be a large number ( 17 for example ). How can I do this ?