Can I run MATLAB function from each excel file using macro at the same time?

조회 수: 12 (최근 30일)
구구
구구 2022년 10월 7일
답변: Eswaramoorthy 2023년 6월 7일
I wanted to run MATLAB function from excel file and it worked using VBA and excel macro.
For parametric study I made several excel file and run the macro from each file.
But when the MATLAB function is running on an excel file, I can not run the function from other excel files.
I want to run same MATLAB function with different inputs at the same time.
Is there any way I can do this?
  댓글 수: 1
dpb
dpb 2022년 10월 8일
Only maybe with the parallel toolbox; but I won't guarantee that, even...but, otherwise both MATLAB and EXCEL are single-threaded.

댓글을 달려면 로그인하십시오.

답변 (1개)

Eswaramoorthy
Eswaramoorthy 2023년 6월 7일
When running MATLAB functions from Excel using VBA macros, MATLAB runs as a separate process and is limited to a single instance. Therefore, running the same MATLAB function with different inputs simultaneously from multiple Excel files is not directly possible.
However, there are a few workarounds you can consider to achieve your goal:
1. Parallel Computing Toolbox: If you have access to the Parallel Computing Toolbox in MATLAB, you can leverage parallel computing to execute the MATLAB function with different inputs simultaneously. Instead of running the MATLAB function from multiple Excel files, you can create a single Excel file that contains all the input data, and then use MATLAB's parallel computing features, such as `parfor` or `parfeval`, to distribute the workload across multiple MATLAB workers.
2. MATLAB Compiler: Another option is to use MATLAB Compiler to compile your MATLAB function into a standalone executable or a shared library. Once compiled, you can call the MATLAB function directly from each Excel file without the need for multiple MATLAB instances. This allows you to execute the MATLAB function with different inputs simultaneously from different Excel files.
3. MATLAB Automation Server: MATLAB Automation Server allows you to remotely control a MATLAB instance from external applications such as Excel using the COM interface. By creating a single MATLAB instance and utilizing the automation server, you can run the MATLAB function with different inputs concurrently from multiple Excel files. This requires some programming in VBA to establish the connection with the MATLAB instance and execute the desired MATLAB functions.
Remember that implementing these workarounds may require additional setup, configuration, and programming, depending on the approach you choose. Consider the complexity of your MATLAB function, the size of the input data, and the resources available to determine the most suitable approach for your specific scenario.
Hope this helps!

카테고리

Help CenterFile Exchange에서 Data Export to MATLAB에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by