Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Guide, load image from folder
Date: Sun, 30 Nov 2008 03:10:19 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 18
Message-ID: <ggt06r$nfm$1@fred.mathworks.com>
References: <ggq8t2$mcg$1@fred.mathworks.com> <ggqa9i$679$1@fred.mathworks.com> <ggqg52$7jo$1@fred.mathworks.com> <ggs8ev$539$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1228014619 24054 172.30.248.37 (30 Nov 2008 03:10:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 30 Nov 2008 03:10:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1343420
Xref: news.mathworks.com comp.soft-sys.matlab:503867


"Rui Gomes" <rpgomes84@gmail.com> wrote in message <ggs8ev$539$1@fred.mathworks.com>...
----------------------------------------
Rui:
I'm not sure why you chose to not use my code and go with something less robust.  You should have used my code.  The problem with your code is that if the user selects a file that is not in the current working directory, your code will throw an error.  This is because you're totally ignoring the folder, which can get returned as an optional return argument from uigetfile().  You need to use fullfile as I had shown you.  Checking for the user clicking the cancel button is a good idea though.  Here is some robust code that will work for any jpg image (the format you seem to want) located in any folder, and also checks for the user clicking the Cancel button:

clc;
[BaseFileName,PathName,FilterIndex] = uigetfile('*.jpg');
if(BaseFileName ~= 0) 
	fullFileName = fullfile(PathName, BaseFileName);
	inputImageArray = imread(fullFileName);
	image(inputImageArray); 
	axis off; 
end 

I suggest you use the above code instead of your code - it will be more robust.  I also suggest you use descriptive variable names.  Many MATLAB users also recommend against the use of i as a variable since it indicates a comples number, but since MATLAB is case sensitive, capital I will be okay, just not that descriptive, especially if you plan on having other image variables in your program.
Regards,
ImageAnalyst