简体   繁体   中英

Matlab: open files 'outside Matlab' by default

I'm looking for a way to have Excel files in my Matlab folder open 'outside Matlab' (ie, by MS Excel in most cases) directly by double-clicking the file, rather than right-clicking and selecting 'Open Outside Matlab'.

The .xls files reader built in Matlab can be terribly slow for large files, and an unwanted double-click on a file can cost quite some time in which Matlab is unresponsive.

Thanks.

When you click something in the Current Folder tab, it's actually running the open command, which itself calls finfo to determine what it means by "open" for a given extension. You can see this by creating a breakpoint in open.m directly after the line [~, openAction] = finfo(fullpath); and double clicking - when it hits the breakpoint you'll see it returns openAction as uiimport .

In theory, you can create custom methods for extensions by creating on the path a function openabc where abc is the extension, which should be returned as the openAction .

However, if I look at my finfo.m it first searches for said functions and then regardless of whether or not it finds them if there is an inbuilt method it overwrites them with the standard behaviour. There's even a comment:

% this setup will not allow users to override the default EXTread behavior

If you are willing to muck about in the inbuilts, you may be able to do it like this (backup first! - this could affect other things). I did it temporarily by shadowing the existing finfo like this:

edit finfo.m (Now save a copy to the current folder)

Add these lines after the loop that defines the openAction (in my version, around line 85):

if any(strcmp(['.' ext], matlab.io.internal.xlsreadSupportedExtensions))
    openAction = 'winopen';
end

From the folder containing your edited finfo.m , type which finfo -all . You should see two copies, the MATLAB one labelled as shadowed. Opening something from the current folder window should now open Excel externally.

I don't believe there's any straightforward way to do that. It's built in to MATLAB that Excel files will open in the import tool when you double click on them, and there's no way to change that.

You might be able to get around it by changing the file extension on your Excel files to something other than .xls or .xlsx . That would stop MATLAB from opening it in the import tool. Then in Windows, you could associate the new file extension with Excel.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM