From: Estee on 21 May 2010 12:37 Hi everyone, I need to input the name of a file, or input the path into a function to load that file. However, that file has to be retrieved from a directory that is not in the current directory. I tried to use addpath('.....'), but putting addpath under the first function line, it doesn't work; MATLAB will just output the error 'no such file or directory' to the input file name. Does anyone know how I can make something like this: function loadFile(filename) %filename becomes a variable to be loaded, and used in the rest of the code Thanks so much! Sorry if this seems stupid but I really tried to do a lot of research on this but couldn't figure it out! Estee
From: dpb on 21 May 2010 12:46 Estee wrote: > Hi everyone, > I need to input the name of a file, or input the path into a function to > load that file. However, that file has to be retrieved from a directory > that is not in the current directory. I tried to use addpath('.....'), > but putting addpath under the first function line, it doesn't work; > MATLAB will just output the error 'no such file or directory' to the > input file name. > Does anyone know how I can make something like this: > function loadFile(filename) > > %filename becomes a variable to be loaded, and used in the rest of the code > > > > Thanks so much! > Sorry if this seems stupid but I really tried to do a lot of research on > this but couldn't figure it out! doc uigetfile % may be of interest doc fullfile % and friends... --
From: ImageAnalyst on 21 May 2010 13:20 Estee: Here's how I'd do it: folder = 'C:\Program Files\MATLAB\R2010a\toolbox\images\imdemos'; if ~exist(folder, 'dir') folder = pwd; end filePattern = [folder, '\*.*']; % Browse for the image file. [baseFileName, folder] = uigetfile(filePattern, 'Specify an image file'); if folder == 0 msgbox('You canceled out'); else fullImageFileName = fullfile(folder, baseFileName); msgbox (['You selected ', fullImageFileName]); imageArray = imread(fullImageFileName ); end
|
Pages: 1 Prev: solving system of non linear equation Next: 2D gaussian fit of image |