Home » excel » excel – Matlab: open files 'outside Matlab' by default

excel – Matlab: open files 'outside Matlab' by default

Posted by: admin April 23, 2020 Leave a comment

Questions:

I’m looking for a way to have Excel files in my Matlab folder open ‘outside Matlab’ (i.e., 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.

How to&Answers:

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.

Answer:

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.