Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

problem about using calllib why I can't show the value on the window of console

Asked by euphy on 20 May 2013

when I ran the program, I can't get the result I expect. the screen can't show the value of these three varibles. this is my C++ function and DynaConfig is a struct

STRUCT_TRANS_C double trans_dynaconfig(DynaConfig *config)
{
	cout<<config->AeroEnable<<endl
		<<config->ArmJnt0<<endl
		<<config->GraspEnable<<endl;
	double a; 
	
	a=config->AeroEnable;
	system("pause");
	return a;
	
}

this is the m code

clc;clear;
loadlibrary('struct_trans','struct_trans.h');
DynaConfig.AeroEnable = 23.6;
DynaConfig.ArmJnt0 = 52;
DynaConfig.GraspEnable = 56.3;
y = calllib('struct_trans','trans_dynaconfig',DynaConfig);
unloadlibrary struct_trans;

0 Comments

euphy

Products

1 Answer

Answer by Philip Borghesani on 20 May 2013
Accepted answer

Calling cout from a mex file or dll does not work on all versions of MATLAB and operating systems. The best solution is to use mexPrintf to output to the MATLAB command window. It is possible that starting MATLAB with the -nodesktop option will give you your output but this is probably not desirable for other reasons.

3 Comments

euphy on 21 May 2013

Thank you so much for your answer! ^_^

Actually the C code is built in VS2010, you mean I use mexPrintf instead of cout, but this just can happen when I code and compose in matlab. what's more I don't understand for nodesktop option, is there something different between start in destop short cut and it?

Walter Roberson on 21 May 2013

The shortcut could in theory include the -nodesktop option, but you would have to configure it to do that. When -nodesktop is not used then the command window and editor and whatever are created and stdin and stdout are created internally in the program in ways that are not connected to cin and cout. When -nodesktop is used then no command window etc. are created and stdin and stdout are connected to cin and cout.

euphy on 21 May 2013

thank you so much !

But I still don't know how to start matlab with the nodesktop option, can you show me the operation steps?

Philip Borghesani

Contact us