unexpected behaviour of uiimport

11 Ansichten (letzte 30 Tage)
Andre Zeug
Andre Zeug am 2 Dez. 2020
Beantwortet: Jemima Pulipati am 16 Dez. 2020
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
uiimport
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.)
Thanks

Akzeptierte Antwort

Jemima Pulipati
Jemima Pulipati am 16 Dez. 2020
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;
uiimport('-file')
% 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})

Weitere Antworten (1)

Jemima Pulipati
Jemima Pulipati am 15 Dez. 2020
Hello,
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 Kommentare
Andre Zeug
Andre Zeug am 16 Dez. 2020
Bearbeitet: Andre Zeug am 16 Dez. 2020
Many thanks for your explanation.
Any idea why Mathworks provide such behaviour?
Is this only an intermediate behaviour in the transition from the import wizard to the import tool?
Is it planned to be changed in further releases?
Technical question: howto label your second reply as "Accept this answer"?
Jemima Pulipati
Jemima Pulipati am 16 Dez. 2020
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.

Melden Sie sich an, um zu kommentieren.

Tags

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by