Add your own alternative version
Stats
959K views 8.8K downloads 92 bookmarked
Posted
27 May 2003

Comments and Discussions


Oooops, I've realized that the values I want to put into my matrix is on the form float. Now I don't see straight away how I can put a mtrix on form float to matlab. Is there a way you know of?
(I can't convert the values to double, cause that changes it dramatically and I can'twrite the matrix inMyP to float and then put it in: memcpy((void *)mxGetPr(myP), (void *)inMyP, sizeof(inMyP));
Have any ideas of how to help me?





Hi AGAIN!
I want to execute own created matlabfiles. This must be possible, right, since I can execute commands? But HOW do I execute own funtions?
I create a matrix in my C++ program, of course I'm not sure that it's well done, but say it is. I can at least send it to matlab and plot it, but that's not good for me, I need to do more complicated stuff and I allready have nice functions in matlab. I've tried to put a file in the same directory as my C++ program and my C++ program compiles with no problems, but when calling my function nothing happens, and no complains either...
I would later on be able to call a function in another directory, would this be possible?
I would be grateful for help!





Just copy your m files in work directory of MATLAB.
A. Riazi





If I have many files it would have been nice to put them into another directory, maybe in this matlab directory, but still. Can I do that? I've tried to call my function by "myDirectory/myFile", but this doesn't work...





For doing this, it's better that you add this directory to Matlab path.
A. Riazi





Hi again!
I wonder if it's possible to show figures from matlab all over the screen or at least at its' own size on top of my Visual Studio window, because now it's only the little indicating box on bottom of the screen which is shown and of course I can click it and look at it, but I would like this action to be automatic. Do you know how to help me here?
THANKS!





You can get figure handle. Use this handle as input parameter for functions like SetWindowPos.
A. Riazi





Hi again!
I'm working with Your code now, I understood that it might be best for me from your last mail. Anyways, I've made the demo compile without any problems, BUT when I run it nothing happens... or the runconsolewindow pops up with the text "Press any key to continue", and it's NOT the messagetext in the MatlabClass.cpp code, cause if I change those texts the consolewindow still shows the same thing. And if I put in a printf(...) as a first line in the main method this print doesn't show in the consolewindow. I really have no idea of what could be wrong. have you perhaps?
(The demo couldn't link correctly before I had added the right paths, of course!)
thanks again and also thank you for your last Quick response!
Astrid





Hi Astrid,
Please write your code here that I can help you.
A. Riazi





I emailed you my code since it's the same as yours anyone (because it's your demo that I can't get to run and wants to understand and play with as a start).
But I wonder if perhaps one must not include too many libraries. Since I in the directory for my libraries have more libs than the ones you say are needed? stupid question I guess..





Hi again!
I've mocked around a bit with the code. Now I only have the code on the bottom of the page, and now I get the following message:
"The instruction on 0x0003a460 refered to the memory on 0x0003a460. It wasn't possible to chenge memory. The following error was returned: The memory could not be read". This feels quite bad, so what can I have missed. Could you help me? Please!!
THE CODE:
#include "stdafx.h"
#include "MatlabEng.h"
#include <time.h> //astrid
#include <stdio.h> //astrid
#include <stdlib.h> //astrid
//#include <iostream.h> //astrid
#include <iostream> //astrid
using namespace std; //astrid
using std::cout; //astrid
using std::cin; //astrid
using std::endl; //astrid
#define message(x) printf(x"\n\n")
int main(int argc, char* argv[]) {
printf("hi 0 \n" );
printf("hi 1 %d\n",a2 );
//return 0;
CMatlabEng matlab;
//open new matlab session
message("Starting MATLAB");
matlab.Open(NULL);
message("Hiding MATLAB");
matlab.SetVisible(FALSE);
message("Press any key to continue 1");
getch();
message("Showing MATLAB");
matlab.SetVisible(TRUE);
message("Press any key to continue 2");
getch();
//close session
matlab.Close();
return 0;
}





SORRY if I stole your time, now I think I've solved the problem anyway.
I had multiple choices on how to chose the path to the libraries. I had chosen the wrong path before, but the program could compile anyway. For me this path was finally the right one:
"C:\MATLAB6p5\extern\lib\win32\microsoft\msvc70"
I just wanted to tell, but thanks anyway!
And thank you so much for the program, now the demo works beautifully and I just hope I can add it correctly and use it in my own code!





I'm very happy that you can solve your problem.
A. Riazi





sir ,
iam new to dsp i want to draw magnitude,phase,,pmpulse response graphs.
i don't know what are all thses also.so iam using matlab functions to calculate thse but it is returning two arrays.
i have seen u r articles in which it is returning only one output
could u pls explain me how to return 2 arrays and how to make(standedalone) my program to run pc which dodn't have matlab.
thank u very much
regards
usha





Dear usha,
There are some useful functions in Matlab to draw magnitude and phase of a signal. for example to draw magnitude of y in y=f(x), you can simply write
plot(x, abs(y)); But here is a restriction. If you have a graph in Matlab, you can not import it in VC. In other word, there is no API that can plot in Visual C++ without using MATLAB engine. For doing this, you must complete your computation with Matlab C API or C++ equivalent class and plot it using third party libraries (like PGL[^]) or using some ActiveX control (2D Graph ActiveX Control[^] or 3D Graph ActiveX Control[^]).
For more information to returning two array from a function, I suggest you two read Matlab C/C++ Math Library carefully or for brief overview, visit my other 2 articles.
Information about creating standalone executable programs that uses Matlab C/C++ API (does not require Matlab) can be found in mentioned articles.
A. Riazi





What's the difference of this article and "A class wrapper for Matlab(c) ActiveX Control" by Jonathan de Halleux?
I'm good at Matlabprogramming, but not as great at C++. But now I have a cameraprogram in C++ where I for each photo would like to call Matlabfunctions directly from my C++ code. So I wonder what should be best for me to use, your stuff or the one from J de H?
I found JdeH's article first and I've been able to run his demo, but I don't do the correct things in my own code so I haven't been able to make it work. I'll ask about my problems on his page... But I wonder if I should rather use your stuff???
I would be grateful for quick responses!





astridwahlin wrote:
What's the difference of this article and "A class wrapper for Matlab(c) ActiveX Control" by Jonathan de Halleux?
My article does not employ an ActiveX control. Here is one simple class that communicates directly with Matlab without any ActiveX!
My code is very simple to use because you write code in Matlab language not C/C++. You need only to transfer commands to Matlab environment. If you want to know more information about C/C++ interface for Matlab, here is links for other articles that I wrote:
A. Riazi





can any one tell me if there is RSA encryption using matlab
Kh_sultan2001@hotmail.com





Try this link. You'll need to change RSA.txt to RSA.m.
http://au.geocities.com/watery_mark/wm/RSA.txt
Hope this helps.





First of all, thanks a lot. Your article is very helpful to me.
But as I'm a biginner of Matlab, I'd like to know some usage of GetVariable(...). .
Please givee me a some usage example of GetVariable function.





Here is an example:
CMatlabEng MyEng;
mxArray* A;
double dblArray[]={1, 2, 3, 4, 5, 6, 7, 8, 9};
A=mxCreateDoubleMatrix(3, 3, mxREAL);
MyEng.PutVariable("MyVar", A);
MyEng.EvalString("MyVar=mlfMagic(3)");
A=MyEng.GetVariable("MyVar"):
mxDestroyArray(A);
A. Riazi





Thank you.
But I don't know that how can I get values from A.
ex)
myfunc()
{
double dbGetValues[3];
mxArray* A;
A=mxCreateDoubleMatrix(1, 3, mxREAL);
MyEng.EvalString("val= [1.0 2.0 3.0]");
A = MyEng.GetVariable("val"):
// How can I get dbGetValues[3] from A?. Please fill the follows
dbGetValues = ????
mxDestroyArray(A);
}





Here is an example:
myP = mxCreateDoubleMatrix(5, 6, mxREAL);
double inMyP[5][6];
memcpy((void*) mxGetPr(myP), (void*) inMyP, sizeof(inMyP));
matlab.PutVariable("myP", myP);
matlab.EvalString("myP=myP.*2;");
myP=matlab.GetVariable("myP");
...
for (int i=0; i<5; i++)
{
for (int j=0; j<6; j++)
printf("%f\t", inMyP[i][j]);
printf("\n");
}
mxDestroyArray(myP);
A. Riazi





Dear sir,
I am trying to calculate the RR interval of ECG waveform using the MATLAB. Can you help me with a sample coding which calculate the peaks of a waveform while the waveform is running continuosly. Is it possible to me to create a user interface
WRgds
rohith





Dear sir,
I am tryiong to calculate the RR interval using the MATLAB. Can you help me with a sample coding. Is it possible to me to create a user interface
WRgds
rohith






General News Suggestion Question Bug Answer Joke Praise Rant Admin Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

