unexpected behaviour of uiimport

7 ビュー (過去 30 日間)
Andre Zeug
Andre Zeug 2020 年 12 月 2 日
回答済み: Jemima Pulipati 2020 年 12 月 16 日
Dear all,
my initial task was to import some *.csv file and return the content and the filename as return variables, such as
[content, filenameSelected] = uiimport;
Using R2020b, I receive different GUIs when calling
without return variable, which opens the new(?) import wizard or calling
A = uiimport;
which opens an old(?) GUI. None of it, provide the file & path name, selected during the wizard.
Question: is there an option to use the new wizard in combination with a return variable, providing the content and the filename?
(Workaround for the latter would be the use of 'uigetfile' before.)


Jemima Pulipati
Jemima Pulipati 2020 年 12 月 16 日
There are two tools that may be used when importing text data. If you specify an output argument when you call uiimport, the Import Wizard is used. When you do not specify an output argument, the Import Tool is used.
The uiimport documentation does also mention about this behaviour.
>> uiimport('txtInput.csv') % Opens the Import Tool
>> s = uiimport('txtInput.csv') % Opens the Import Wizard
The Import Tool was built to handle many more types of files and variations than the Import Wizard. In many cases, it produces better results, and provides many more controls over the output.
The Import Tool will directly create variables in the workspace, or alternatively, the user can generate a script or a function to use in their code to do the import.
Please note that there is no way to enforce or use the Import Tool in synchronous mode like this (i.e combining and retrieving data into an output variable).
Another workaround that I can suggest is using a command line prompt
vars = [];
vars = whos;
% hit enter on the command window after doing the import
input('Hit enter when done importing...')
vars2 = whos;
% newvars has the name of the file that was selected for import
newvars = setdiff({vars2.name},{vars.name})

その他の回答 (1 件)

Jemima Pulipati
Jemima Pulipati 2020 年 12 月 15 日
From my understanding, you want to retrieve the file name and path while making a selection using uiimport().
Currently, uiimport() does not give any output arguments containing the filename or the path. It only returns the imported data from the selected file.
You can use the following the workarounds:
  • Using uigetdir() along with uiimport(): uigetdir() lets the user select a folder and returns the selected path of the folder, while uiimport() stores the filename as the field name while creating the struct with the imported data. Both these values can be concatenated using fullfile() to generate the complete path of file selected. fieldnames() returns the field names inside the struct which is the actual file name selected.
S = uiimport();
% gets the path of the folder selected. The folder in which the .csv file is present has to be selected
selpath = uigetdir;
% displays the entire concatenated path
file = fullfile(selpath,fieldnames(S))
  • Using uigetfile(): This returns the file name and path name as separate output arguments while selecting the file
[FileName,PathName,FilterIndex] = uigetfile('.csv')
  4 件のコメント
Jemima Pulipati
Jemima Pulipati 2020 年 12 月 16 日
This is a know issue to MathWorks and this behaviour may be changed in future releases.
Currently, there is no option of accepting a comment as an answer in the Community unless it is posted as an Answer. I will try moving the comment to Answers section, maybe you can accept that.



Help Center および File ExchangeMATLAB Report Generator についてさらに検索





Community Treasure Hunt

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

Start Hunting!

Translated by