Add your own alternative version
Stats
305.8K views 2.9K downloads 50 bookmarked
Posted
24 May 2003
|
Comments and Discussions
|
|
please tell me how can i use matlab functions in msvc while i am using matlab 7(r14) and msvc 6.0............
|
|
|
|
|
|
Hi,
I have written a traffic simulator based on C language, and I launch it using the Matlab engine functionality after compiling it with LCC.
Everything works well as long as I only pass single double variable from the simulator to the Matlab workspace. But I can't find a way to pass the whole Matrix, which is 28x5700.
I could not adapt the examples I have read here (using memcpy), probably I miss some background on this topic.
I have been striving against this for some weeks and any help will be very appreciated.
Thank you
Stefano.
|
|
|
|
|
Hello Cambalindo
Thank you for the perfect project and beautipfu explanation. Iwell compiled your project, but when I start it and when I press "CONV" button the Error box appears which is saying about "Invalid property value".
How do I can reapare that ?
That message appears in WINCORE.CPP file in such place
CATCH_ALL(e)
{
CWinThread* pWinThread = AfxGetThread();
if ( pWinThread != NULL )
{
lResult = pWinThread->ProcessWndProcException(e, &pThreadState->m_lastSentMsg);
TRACE1("Warning: Uncaught exception in WindowProc (returning %ld).\n",
lResult);
}
else
{
TRACE0("Warning: Uncaught exception in WindowProc.\n");
lResult = 0;
}
DELETE_EXCEPTION(e);
}
when is executing this code part in CONV button function
if(n<11)
{
m_Chart.SetColumn(1);
m_Chart.SetRow(n+1);
value=do2CStr(x1[n]);
m_Chart.SetData(value);
m_Chart.SetColumn(2);
m_Chart.SetRow(n+1);
value=do2CStr(x2[n]);
m_Chart.SetData(value);
}
|
|
|
|
|
Hi,vitamine, thanks for your words regarding the article.
It's really annoying that it's not working for you, and unfortunately I don't have an answer for your error, could you tell me what Matlab and VS versions are you using?
regards.
Daniel Cespedes
"There are 10 types of people, those who understand binary and those who do not"
"Santa Cruz de la Sierra Paraiso Terrenal!"
daniel.cespedes@ieee.org
|
|
|
|
|
MATLAB version is 6.5 or VS according to the article - 6.0. I gess that problem is with visualisation, because in initialisation of graph window defined 10 points (input data), after convolition we get 16 points. In my opinion is something wrong with reinitialisation.
|
|
|
|
|
perhaps, you could try without the mschart, comment all the lines corresponding to the chart, and see if your function is working. If it works, the problem es in the chart part, I'll review it to see if I can find the error.
cheers
Daniel Cespedes
"There are 10 types of people, those who understand binary and those who do not"
"Santa Cruz de la Sierra Paraiso Terrenal!"
daniel.cespedes@ieee.org
|
|
|
|
|
Hi,
Could you give me idea on this errors? I am currently using Matlab 7.5.0(2007b) and Microsoft Visual c++ 6.
Please. thank alot.
c:\documents and settings\administrator\desktop\matlab_add_in\myfunc.h(21) : fatal error C1083: Cannot open include file: 'libmatlb.h': No such file or directory
MyFunc_main.c
c:\documents and settings\administrator\desktop\matlab_add_in\myfunc_main.c(14) : fatal error C1083: Cannot open include file: 'libmatlb.h': No such file or directory
Error executing cl.exe.
Build : warning : failed to (or don't know how to) build 'E:\trabajos\daniel\practicasC++\conv\MyFunc.m'
|
|
|
|
|
Hi, pls. see the thread right below this one, I think your errors are addressed there.
another thing:
the last warning, is addressing my HardDisk:
Error executing cl.exe.
Build : warning : failed to (or don't know how to) build 'E:\trabajos\daniel\practicasC++\conv\MyFunc.m'
check that should be your path to your function.
regards
Daniel Cespedes
"There are 10 types of people, those who understand binary and those who do not"
"Santa Cruz de la Sierra Paraiso Terrenal!"
daniel.cespedes@ieee.org
|
|
|
|
|
I had matlab 7.0 and the mccsavepath command doesn't work anymore, this is because this version of matlab supposedly 'automatically' adds its path to the windows path. this is not necessarily done right and can be corrected manually. See instructions here and add you matlab bin directory to the path, for example on my computer I copied this to my path:
C:\Program Files\MATLAB\R2007a\bin
C:\Program Files\MATLAB\R2007a\bin\win32
also, make sure your visual c++ bin directory is in the same path, on my computer:
C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin
Before I discovered this I reinstalled an older version of matlab that did have a working mccsavepath command, matlab 6.5 (release 13). in matlab 6.5 I typed in the commands as this article shows and they worked ok, but then I still had to go into the windows path and manually make sure that the matlab and vc++ bin directories were in the windows path:
c:\matlab6p5\bin\win32
C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin
|
|
|
|
|
IN ADDITION:
some of you asked about mlfMyFunc undeclared identifier errors. The way to fix this is to open the myfunc.h file, and look to see what the corrrect capitalization is of the function, it should be around line 26 of the .h file. the capitalization seems to be arbitrary so make sure you check, for me it was mlfMyfunc() even though the .h file was myfunc.h and my m-file function was MyFunc()
|
|
|
|
|
here's how I finally got everything to work. read my advice in the two comments above (check capitalization of myfunc, include bin directories in the widnows PATH, etc.
%+++++++++++++++++++++++++++++++++++
%+++++++++--MATLAB M FILE--+++++++++
%+++++++++++++++++++++++++++++++++++
function out=MyFunc(a,b)
if ( a >= b)
out = a;
else
out = b;
end
%+++++++++++++++++++++++++++++++++++
//###################################
//#########--VC++ Code Below--#######
//###################################
//#######library modules linked to project:#########
// libmwlapack.lib libmex.lib libmx.lib
//include section
#include "stdafx.h"
#include "MatlabIntegrationTest.h"
#include "MatlabIntegrationTestDlg.h"
#include "matlab.h"
#include "myfunc.h"
#include "mat.h"
#include "conio.h"
#include <iostream.h>
/*
this part below is in the OK buttons function
I modified the code posted in the instructions to be simpler
my code sends two numbers, x1 and x2 to the m-file, the m-file
decides which number is larger and sends it back to the c++ code
---
you can see the unmodified original code in the comments above each
line of my modified code
---
In order to see that the code was working correctly, I made an 'edit box'
in my GUI dialog, the variable associated with the edit box is m_Output
So at the end of my code I write the value returned to the c++ code from the
m-file to the edit box so you can see it. In the case of the two numbers I'm
sending the m-file in my code (4 and 6), it should show a 6 when you click the
GUI's ok button to run the program.
*/
void CMatlabIntegrationTestDlg::OnOK()
{
//double x1[]={1,2,3,4,5,6,7,8,9,0};
//double x2[]={4,5,6,7,4,5,8,9,0,7};
double x1[]={6};
double x2[]={4};
//double res[19];
double res[1];
//create the arrays that will be passed to MyFunc
mxArray* In1;
mxArray* In2;
mxArray* Out;
//we make them Real and have 10 values
//In1=mxCreateDoubleMatrix(1,10,mxREAL);
//In2=mxCreateDoubleMatrix(1,10,mxREAL);
In1=mxCreateDoubleMatrix(1,1,mxREAL);
In2=mxCreateDoubleMatrix(1,1,mxREAL);
//this make In1=x1;In2=x2
//memcpy(mxGetPr(In1),x1,10*sizeof(double));
//memcpy(mxGetPr(In2),x2,10*sizeof(double));
memcpy(mxGetPr(In1),x1,1*sizeof(double));
memcpy(mxGetPr(In2),x2,1*sizeof(double));
//Call to MyFunc.m that return the convolution of In1 and In2
Out=mlfMyfunc(In1,In2);
//now we have the result(Out) in a double array 'res'
//memcpy(res,mxGetPr(Out),19*sizeof(double));
memcpy(res,mxGetPr(Out),1*sizeof(double));
//send the returned value to an edit box of the GUI
double LeeOut;
LeeOut = res[0];
m_Output = LeeOut;
UpdateData(FALSE);
//extra debug message
MessageBox("hi");
//Destroy matrices
mxDestroyArray(Out);
mxDestroyArray(In1);
mxDestroyArray(In2);
}
|
|
|
|
|
Thanks leevonk!!
for clarifying some of the doubts posted, and making the sample easier to implement!!
I haven't looked this article for a while...
cheers!
Daniel Cespedes
"There are 10 types of people, those who understand binary and those who do not"
"Santa Cruz de la Sierra Paraiso Terrenal!"
daniel.cespedes@ieee.org
|
|
|
|
|
I have the same exact proplem as the following and i have matlab R2007b :
I follow the instruction to
Configure the Matlab Add-in for Visual Studio 6 to work within MSVisual C++:
by Open MSVisualC++, Select Tools -> Customize from the MSVC menu.
Clicking on the Add-ins and Macro Files tab.
but i dont see any MATLAB for Visual Studio on the Add-ins or Macro Files list ,
i also type the command in MAATLAB:
cd(prefdir) ;
save mccpath;
|
|
|
|
|
sir,
I used the example to build an Vc++6.0 application which use matlab function and yhe application run well. my problem is when i execute my application to the another computer i have some errors. how can i generate the executable file of my application?
|
|
|
|
|
Can you send me the error messages in the other computer you try to run..
does the other computer has VC++ insalled, if not you may be need some dlls to copy.
Daniel Cespedes
"There are 10 types of people, those who understand binary and those who do not"
"Santa Cruz de la Sierra Paraiso Terrenal!"
daniel.cespedes@ieee.org
|
|
|
|
|
this is my first time to come here.I also have the problem that is same as Joel Karbassi .My matlab release is 7.1. I also cannot see the button in MSVC. I'm glad to hear from you and thank you!
|
|
|
|
|
i follow the instruction to
Configure the Matlab Add-in for Visual Studio 6 to work within MSVisual C++:
by Open MSVisualC++, Select Tools -> Customize from the MSVC menu.
Clicking on the Add-ins and Macro Files tab.
but i dont see any MATLAB for Visual Studio on the Add-ins or Macro Files list ,
i also type the command in MAATLAB:
cd(prefdir) ;
save mccpath;
sincerely Joel
|
|
|
|
|
what matlab version do you have?
Daniel Cespedes
"There are 10 types of people, those who understand binary and those who do not"
"Santa Cruz de la Sierra Paraiso Terrenal!"
daniel.cespedes@ieee.org
|
|
|
|
|
I have MATLAB2009a and MSVC 2008
|
|
|
|
|
I'm new to MATLAB programming. I currently use MATLAB v6.1(R12) on
MS WINXP SP2 with MS Visual C++ (6.0). I created a section of a
program within the Visual C++ environment and inserted a function
M-file into this program using the MATLAB Visual Studio Add-in. The
function M-file is to produce graphical output based on the values of
arrays which are to be initialized in the C++ environment. The
resulting program shows no compile errors.
The problem begins when the program is executed. It seems unable to
use the arrays intialized within the Visual C++ environment and
returns the error: "variable x is undefined". I don't understand why
this is so as the arrays have been initialized and passed
(mwArray(n_,_n,_name). I would appreciate it if someone could
provide assistance urgently.
Thank you
ATBU
|
|
|
|
|
I'm new to MATLAB programming. I currently use MATLAB v6.1(R12) on
MS WINXP SP2 with MS Visual C++ (6.0). I created a section of a
program within the Visual C++ environment and inserted a function
M-file into this program using the MATLAB Visual Studio Add-in. The
function M-file is to produce graphical output based on the values of
arrays which are to be initialized in the C++ environment. The
resulting program shows no compile errors.
The problem begins when the program is executed. It seems unable to
use the arrays intialized within the Visual C++ environment and
returns the error: "variable x is undefined". I don't understand why
this is so as the arrays have been initialized and passed
(mwArray(n_,_n,_name). I would appreciate it if someone could
provide assistance urgently.
Thank you
ATBU
|
|
|
|
|
On VS2003 I get mbuild -setup and mex- setup to work and can build mex files (from .c/.cpp code and .m code). I did this (in case anyone wants to know) by making a copy of the VC folder in the visual studio .net folder and naming it Vc7 (as this is where matlabs mbuild -setup script looks for the cl.exe compiler).
I could also get the Visulal Studio. However the add-in, that should be made availeble after running the mbuild -setup, is not availeble because the tools-customize dialogue is not the same as in VC++ 6. Also the (copied) Vc7 folder is not accessed by VS2003 .net so, if this is where the add-in is placed it will not be found.
To overcome this I used the MatLab VS.Net Custom App Wizard (see matlab exchange) to allow me to start a mex project using the VS IDE new project wizard. This was fine.
Now I have upgraded to VS2005 and things are not so good.
On VS2005 I can get the mex -setup and mbuild -setup scripts to run successfully (by doing the same copying <vc> and calling it <vc7> trick) but this time the .dlls dont work. Also I have tried the MatLab VS.Net Custom App Wizard and although I can get the wizard to create the project, the project no longer compiles.
If anyone has sorted this out yet please let me know. Also, if your using VS2003 then try my trick of creating the Vc7 folder in the VS.NET2003 folder.
cheers,
lIAmO,
lets help each other make coding easier.
|
|
|
|
|
Hi, my name is Ray, can I help you?
I have a function (piecewise) in matlab's editor
function y = fdp1(x)
if (x < 0)
y=0;
elseif (x >= 0 & x < 1)
y=(1/2)*x.^2;
elseif (x >= 1 & x < 2)
y=1/2;
elseif (x >= 2 & x < 4)
y=(1/4)*x;
else x >= 4
y=1;
end;
______________
When I want to plot,
It's don't plot
Why?
|
|
|
|
|
Hola,en primer lugar te expreso mis saludos y agradecerte pues este tutorial e ha servido mucho.Ahora te quiero hacer una pregunta: lo que yo deseo es leer una funcion en visual c++ usando el add in pero en esta función yo guardo variables como archivos .mat para luego cargarlos con load en otra función y poder trabajar en esa. ¿Cómo puedo trabajar con estos archivos?.Te agradeceré mucho tu ayuda.
Hector Villacorta
|
|
|
|
|
|
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.
|
|