b3.
b3.

Reputation: 7165

Drag and drop to MATLAB command window

When a file is dragged-and-dropped from the operating system to the MATLAB command window, MATLAB runs the uiopen command to import the data file. Depending on the file type, this may result in the import tool being displayed. In other cases, it leads to direct importing of the data in the file.

Is it possible to customize this process based on the file type? Perhaps I can hook into the drag-and-drop event itself or extend uiopen or extend the import tool or something else...?

Upvotes: 3

Views: 738

Answers (1)

b3.
b3.

Reputation: 7165

Ended up accomplishing this by editing uiimport.m. Added the following after the import statements:

if nargin == 1
    possibleDroppedFile = varargin{1};
    if isstring( possibleDroppedFile ) ...
            && exist( possibleDroppedFile , 'file') == 2
        fileContent = myFileParser( possibleDroppedFile );
        assignin( 'base', 'fileContent', fileContent );
        return;
    end
end

Of course, how you parse the file is specific to your application but this gives you the gist.

Upvotes: 1

Related Questions