Getting Windows to open a file type using a MATLAB application

3 次查看(过去 30 天)
I'd like to create a MATLAB application that can be used by Windows as the default program for opening certain file types. What I'm imagining is creating an app that reads an Excel file and processes and displays the information in a certain way. I would save an Excel file as something.xls2, and when I click on it in the file explorer, it would start my MATLAB application and pass it the filepath of something.xls2 so that the app can read the data and do it's thing. If this is possible then I'm sure it would involve some fiddling with Windows as well as MATLAB, but any insight would be appreciated.

回答(2 个)

Rik
Rik 2021-5-28
You should be able to compile your function and use the 'open with' dialog in Windows to assign it to your exe.
If you let your function accept the path as input this should work without any tricks.
See this doc page.

per isakson
per isakson 2021-5-28
编辑:per isakson 2021-6-1
An alternative that doesn't require the Matlab compiler (but requires a Matlab license to run):
  • Create a bat-file, e.g. read_xls2.bat (See Guide to Windows Batch Scripting). (Or a PowerShell script.)
  • Right click an xls2-file, click "Open with ...", and choose read_xls2.bat as "Always open with"
  • Create an m-file, read_and_process_xls2.m, that does the job.
  • read_xls2.bat shall contain a command that starts Matlab, see matlab (Windows), Start MATLAB program from Windows system prompt and Commonly Used Startup Options. The name of the xls2-file that you double click will be available in the batch file under the name "%1" (and "%*"). The strings "read_and_process_xls2", "-batch" (or "-r") and "%1" shall appear in the command line that starts Matlab.
I made a tiny demo. Double clicking echo.abc invokes echo.bat
ECHO %0
ECHO %1
ECHO %*
pause
outputs
D:\m\cssm>ECHO "D:\m\cssm\echo.bat"
"D:\m\cssm\echo.bat"
D:\m\cssm>ECHO "D:\m\cssm\echo.abc"
"D:\m\cssm\echo.abc"
D:\m\cssm>ECHO "D:\m\cssm\echo.abc"
"D:\m\cssm\echo.abc"
D:\m\cssm>pause
Press any key to continue . . .

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by