Prev: error with xmlread
Next: uitable
From: Viperstd on 7 Jan 2010 10:50 I am having a problem with UIGETFILE taking a default directory path. I am trying something similar to this on a windows machine: >> [fn path]=uigetfile('F:\test1\test2\test3\*.jpg','Select a jpg','default.jpg') The popup box appears in the working directory instead of F:\..\..\test3\ as I am specifying. I have tried both '/' and '\' without any success. For example, I tried this: >>[a b]=uigetfile('F:\test1\test2\test3\*.jpg','Select a jpg','default.jpg') It opens in the working directory instead of where it should. If I navigate to the right place and select a file: a = 346B.jpg b = F:\test1\test2\test3\ >> tst=fullfile(b,a) tst = F:\test1\test2\test3\346B.jpg >> [a b]=uigetfile(tst,'Select a jpg','default.jpg') …opens in the working directory! I am stuck. Thank you for your help.
From: Viperstd on 7 Jan 2010 12:16 is this a versionism? I am running 7.7.0 R2008b
From: Jan Simon on 7 Jan 2010 12:19 Dear Viperstd! > I am trying something similar to this on a windows machine: > >> [fn path]=uigetfile('F:\test1\test2\test3\*.jpg','Select a jpg','default.jpg') > > The popup box appears in the working directory instead of F:\..\..\test3\ as I am specifying. I have tried both '/' and '\' without any success. The 2nd input FILTERSPEC of UIGETFILE does not consider the folder. As far as I understand, this is in agreement with the documentation. One solution: function File = uigetfileCD(FileSpec, Message, Default) FileSpec = 'F:\test1\test2\test3\*.jpg'; [fPath, fName, fExt] = fileparts(FileSpec); backDir = cd; cd(fPath); [FileName, FilePath] = uigetfile([fName, fExt], Message, Default); if ischar(FileName) File = fullfile(FilePath, FileName); else File = 0; end cd(backDir); return; This would be a nice feature in UIGETFILE. But remember, that the FileSpec can be a more complicated cell also: {'*.m;*.c', 'Matlab and C files'; '*.*', 'All files'} Then FILEPARTS will fail with proud! Therefore bakCD=cd(YourPath); choose the file; cd(bakCD) is actually part of the program, not of the file chooser. There have been a similar post about default paths for PUTFILE today: http://www.mathworks.com/matlabcentral/newsreader/view_thread/269785 Kind regards, Jan
From: Viperstd on 7 Jan 2010 12:29 "Jan Simon" <matlab.THIS_YEAR(a)nMINUSsimon.de> wrote in message <hi5529$i52$1(a)fred.mathworks.com>... > Dear Viperstd! > > > I am trying something similar to this on a windows machine: > > >> [fn path]=uigetfile('F:\test1\test2\test3\*.jpg','Select a jpg','default.jpg') > > > > The popup box appears in the working directory instead of F:\..\..\test3\ as I am specifying. I have tried both '/' and '\' without any success. > > The 2nd input FILTERSPEC of UIGETFILE does not consider the folder. As far as I understand, this is in agreement with the documentation. > > One solution: > function File = uigetfileCD(FileSpec, Message, Default) > FileSpec = 'F:\test1\test2\test3\*.jpg'; > [fPath, fName, fExt] = fileparts(FileSpec); > backDir = cd; > cd(fPath); > [FileName, FilePath] = uigetfile([fName, fExt], Message, Default); > if ischar(FileName) > File = fullfile(FilePath, FileName); > else > File = 0; > end > cd(backDir); > return; > > This would be a nice feature in UIGETFILE. But remember, that the FileSpec can be a more complicated cell also: > {'*.m;*.c', 'Matlab and C files'; '*.*', 'All files'} > Then FILEPARTS will fail with proud! > Therefore > bakCD=cd(YourPath); choose the file; cd(bakCD) > is actually part of the program, not of the file chooser. > > There have been a similar post about default paths for PUTFILE today: > http://www.mathworks.com/matlabcentral/newsreader/view_thread/269785 > > Kind regards, Jan Jan, thank you for the reply. I will try your code momentarily. However, I am confused as to filterspec not accepting a path. Per the help file: "[FileName,PathName,FilterIndex] = uigetfile(FilterSpec) displays only those files with extensions that match FilterSpec. The uigetfile function appends 'All Files' to the list of file types.FilterSpec can be a string or a cell array of strings, and can include the * wildcard. If FilterSpec is a string that contains a filename, the filename is displayed and selected in the File name field and the file's extension is used as the default filter. If FilterSpec is a string, it can include a path. That path can contain '.','..', or '/'. For example, '../*.m' lists all M-files in the directory above the current directory." Does this not indicate that you _can_ specify the folder?
From: Jan Simon on 7 Jan 2010 18:59 Dear Viperstd! > If FilterSpec is a string, it can include a path. That path can contain '.','..', or '/'. For example, '../*.m' lists all M-files in the directory above the current directory." > > Does this not indicate that you _can_ specify the folder? You are right. And in fact: It works under Matlab 7.8 and 6.5 on WinXP. I've just read the help section and the FilterSpec with path appears in the doc only. Please try again: uigetfile('..\*.*') Confused, Jan
|
Pages: 1 Prev: error with xmlread Next: uitable |