I have c++ coded exe function with multiple input in windods7.

조회 수: 1 (최근 30일)
mahesh
mahesh 2014년 4월 30일
답변: Prateekshya 2024년 10월 17일
I have c++ coded exe function with multiple input in 64 bit windods7. I want to know how do i call exe file function in matlab 2013a. so that i can compile the programme. plz help.

답변 (1개)

Prateekshya
Prateekshya 2024년 10월 17일
Hello Mahesh,
To call a C++ executable (`.exe`) from MATLAB, you can use the system or ! command to execute the program directly from the MATLAB environment. Here is a step-by-step guide on how you can achieve this:
Step 1: Prepare Your Executable
Ensure that your C++ executable is compiled and ready to be executed. You should know the exact command-line arguments it requires.
Step 2: Use the system Command in MATLAB
You can call your executable using the system function. This function allows you to execute operating system commands from within MATLAB.
% Define the path to your executable
exePath = 'C:\path\to\your\program.exe';
% Define any arguments your program needs
arguments = 'arg1 arg2 arg3'; % Replace with actual arguments
% Construct the command string
commandStr = sprintf('"%s" %s', exePath, arguments);
% Call the executable
[status, cmdout] = system(commandStr);
% Check the status
if status == 0
disp('Execution successful:');
disp(cmdout); % Display the output from the executable
else
disp('Execution failed:');
disp(cmdout); % Display the error message
end
Step 3: Handle Input and Output
  • Input Arguments: If your executable requires inputs, pass them as part of the arguments string. Ensure that the arguments are formatted correctly for the command line.
  • Output Handling: The system function captures the standard output and error streams of the executable. You can use cmdout to process or display this output within MATLAB.
Step 4: Alternative Using ! Operator
Alternatively, you can use the ! operator to execute the command:
!C:\path\to\your\program.exe arg1 arg2 arg3
This method is simpler but does not capture the output or status code in MATLAB variables.
I hope this helps!

카테고리

Help CenterFile Exchange에서 Debugging and Analysis에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by