Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6741285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:42:24+00:00 2026-05-26T11:42:24+00:00

When I open MATLAB, it defaults to open to /home/myUser . Whenever I open

  • 0

When I open MATLAB, it defaults to open to /home/myUser. Whenever I open a file interactively (say I run Simulink and click “Open…”) the dialog will start in /home/myUser. Then I might go into /home/myUser/myDir1/myDir2/ before clicking on myModel.mdl.

If I open a different Simulink file with the “Open…” dialog again, it’ll kick me back to /home/myUser. Note that this is regardless of file, I’m just using Simulink as an example. I would like to keep it in /home/myUser/myDir1/myDir2, meaning I should be in the same directory as the last file I just opened (or saved).

Programatically, I would set up a callback to cd into whatever directory the file I chose was in after selecting the file using uigetfile. Is this possible to do just with MATLAB’s own “Open” or “Save As” commands?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T11:42:24+00:00Added an answer on May 26, 2026 at 11:42 am

    There is a wrapper for uigetfile that remembers the last director on the file exchange. You can get wrappers for the other file dialogs as well from the same author.

    EDIT

    How to overload the built-in uigetdir etc.

    (1) Rename uigetdir2 to uigetdir, and make sure it’s in a path that has precedence over the path for the built-in function (this should be the case by default).

    (2) Use BUILTIN to ensure that the new function doesn’t call itself.

    (2) Since uigetdir is implemented as a .m-file, as opposed to being compiled (like sum), the builtin command doesn’t work for it. Thus, open uigetdir, find the private function uigetdir_helper (which is private, so we can’t call it), and finally uncover the java method (that turns out to have changed from R2011a to R2011b. Yay.). This allows us to finally overload uigetdir at the cost of having to parse the input ourselves.

    Here’s lines 37 to 67 from the modified uigetdir

    %% Check passed arguments and load saved directory
    % if start path is specified and not empty call uigetdir with arguments
    % from user, if no arguments are passed or start path is empty load saved
    % directory from mat file
    
    % parse inputs
    parserObj = inputParser;
    parserObj.FunctionName = 'uigetdir';
    parserObj.addOptional('startPath',[],@(x)exist(x,'dir'));
    parserObj.addOptional('dialogTitle','Please choose directory',@ischar);
    
    parserObj.parse(varargin{:});
    inputList = parserObj.Results;
    
    
    % create directory dialog instance - this has changed from 2011a to 2011b
    if verLessThan('matlab','7.13')
        dirdlg = UiDialog.UiDirDialog();
    else
        dirdlg = matlab.ui.internal.dialog.FolderChooser();
    end
    dirdlg.InitialPathName = inputList.startPath;
    dirdlg.Title = inputList.dialogTitle;
    
    
    if nargin > 0 && ~isempty(inputList.startPath)
        % call dirdlg instead of uigetdir to avoid infinite recursion
         dirdlg.show();
    
        % if dirname empty, return 0 for uigetdir.
        directory_name = dirdlg.SelectedFolder;
    else
        % set default dialog open directory to the present working directory
        lastDir = pwd;
        % load last data directory
        if exist(lastDirMat, 'file') ~= 0
            % lastDirMat mat file exists, load it
            load('-mat', lastDirMat)
            % check if lastDataDir variable exists and contains a valid path
            if (exist('lastUsedDir', 'var') == 1) && ...
                    (exist(lastUsedDir, 'dir') == 7)
                % set default dialog open directory
                lastDir = lastUsedDir;
            end
        end
    
        dirdlg.InitialPathName = lastDir;
    
        % call dirdlg instead of uigetdir to avoid infinite recursion
         dirdlg.show();
    
        % if dirname empty, return 0 for uigetdir.
        directory_name = dirdlg.SelectedFolder;
    
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The Open button on the open file dialog used in certain windows applications includes
Is there a way to open a pcode file (.p) in MATLAB?
I want to start a new Open source project regarding natural math and Matlab,
Is there an open-source alternative to MATLAB's fmincon function for constrained linear optimization? I'm
Open source implementation will be preferred.
I am trying to open a specific page within a .chm file from a
I am trying to run the example code from the MATLAB Doc, but when
Anyone out there used MATLAB's javaObject() function with a JAR file that uses JNI?
Matlab is failing to read in the specified number of elements from a file.
I was wondering if anyone knows how to open and read from a file

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.