Listbox GUI

  • Follow


How would I make my code, so that the wav files from the current directory load onto the listbox for the gui?
0
Reply Keyur 8/13/2010 7:04:04 PM

Keyur Patel wrote:
> How would I make my code, so that the wav files from the current 
> directory load onto the listbox for the gui?

Use dir() to get the file information. Extract the name information from the 
structure array returned by dir(). Build either a character array or cell 
array of strings from those names, and use that character array or cell array 
as the value of the String property of the listbox .
0
Reply Walter 8/13/2010 7:15:37 PM


On Aug 13, 3:04=A0pm, "Keyur Patel" <patel_...@yahoo.com> wrote:
> How would I make my code, so that the wav files from the current director=
y load onto the listbox for the gui?

Here's some code.  The adaptation to list only wav files is
straightforward.
Put a call to this function in your callback of your "Specify
Folder..." button or menu item, or in your startup code..
IMPORTANT:  you may need to join any lines split into two by the
newsreader.

%=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
% --- Load up the listbox with image files in folder
handles.handles.ImageFolder
function handles=3DLoadImageList(handles)
	ListOfImageNames =3D {};
	folder =3D handles.ImageFolder;
	if ~isempty(handles.ImageFolder)
		if exist(folder,'dir') =3D=3D false
			msgboxw(['Folder ' folder ' does not exist.']);
			return;
		end
	else
		msgboxw('No folder specified as input for function LoadImageList.');
		return;
	end
	% If it gets to here, the folder is good.
	ImageFiles =3D dir([handles.ImageFolder '/*.*']);
	for Index =3D 1:length(ImageFiles)
		baseFileName =3D ImageFiles(Index).name;
		[folder, name, extension, version] =3D fileparts(baseFileName);
		extension =3D upper(extension);
		switch lower(extension)
		case {'.png', '.bmp', '.jpg', '.tif', '.avi'}
			% Allow only PNG, TIF, JPG, or BMP images
			ListOfImageNames =3D [ListOfImageNames baseFileName];
		otherwise
		end
	end
	set(handles.lstImageList,'string',ListOfImageNames);
    return
0
Reply ImageAnalyst 8/13/2010 8:45:02 PM

hi.. i am refering to this for same purpose... I m working on listing song name to listbox. But i can't compile the code correctly..
i think i might missed out something..

Below is the thing i have tried out for the code... please correct me what else i missed out...

1) I created a folder named "ImageFolder" and then i kip all my .wav and .wma files in that folder.
2) I rewrite the case part to    [case {'.wav', '.wma'} ]  
3) I commented the 1st line of command [handles.handles.ImageFolder]. I wonder it is a part of code? As far i noe, the script should started with [function .....]

Then i compile the code... but it doesn't work... please guide me how can i make it correct?? 

I am very new to GUIDE... sorry that i seem like dunno how the thing works.

Many Thanks.
0
Reply st 2/9/2011 6:34:03 AM

st:
Does you actually call
handles=LoadImageList(handles)
somewhere, like in the OpenFcn()?

By the way, that "first" line is just a line that the newsreader split
- it was supposed to be on the line above as part of the comment.

Explain exactly what "doesn't work" means - is there and error
message, or not error message but nothing gets listed?  Do you know
how to debug code?  Set a breakpoint in the function - do you ever
actually get there?
0
Reply ImageAnalyst 2/9/2011 11:21:18 AM

Hi,

I have 2 .m files and 1 .fig file
1) ListBox.m
2) ListBox.fig (In here, i got a listbox and a push button)
3) LoadImageList.m (In here, i put the code of yours for the wav file listing in ListBox)

I put this 
handles=LoadImageList(handles);
under the pushButton callback function.


Below is the error message that i got:
-----------------------------------------------------------------------------------------------------------
??? Reference to non-existent field 'ImageFolder'.

Error in ==> LoadImageList at 5
folder = handles.ImageFolder;

Error in ==> comboAndListbox>pushbutton1_Callback at 127
handles=LoadImageList(handles);

Error in ==> gui_mainfcn at 96
        feval(varargin{:});

Error in ==> comboAndListbox at 42
    gui_mainfcn(gui_State, varargin{:});

??? Error while evaluating uicontrol Callback
-----------------------------------------------------------------------------------------------------------

I don't understand the 1st error.. i ady declared a ImageFolder in the workspace..
Why it still stating can not find ImageFolder..

Many Thanks
0
Reply st 2/9/2011 5:38:03 PM

Apparently you don't have handles.ImageFolder.  Did you ever assign it
anywhere?  Did you assign it, or ask the user for it via uigetdir()?
Exactly how and where did you assign it for the first time?  If you
had used the debugger and examined handles, you would have seen that
ImageFolder was not a member of the handles structure.
0
Reply ImageAnalyst 2/9/2011 5:53:41 PM

I did some findings that..

The handles. is always comes for UI.. 

For the case above,

what kind of UI that ImageFolder are actually referring to???

Many Thanks...
0
Reply st 2/9/2011 6:06:04 PM

On Feb 9, 1:06=A0pm, "st " <cell...@hotmail.com> wrote:
> I did some findings that..
>
> The handles. is always comes for UI..
>
> For the case above,
>
> what kind of UI that ImageFolder are actually referring to???
>
> Many Thanks...

-------------------------------------------------------------
You need to create the ImageFolder member.  For example, in the
OpenFcn function of your GUI, you can say
handles.ImageFolder =3D 'c:\myImages';
Did you do that?  Can you search for this: "handles.ImageFolder =3D " ?
Did you get any hits?  If no, then you did not assign anything, and
you need to do that.

ImageFolder does not refer to ANY UI.  It's your UI, for example the
one you created in GUIDE, that refers to handles, and it's member
handles.ImageFolder.
0
Reply ImageAnalyst 2/9/2011 6:12:27 PM

8 Replies
526 Views

(page loaded in 0.102 seconds)

Similiar Articles:













7/25/2012 9:38:33 PM


Reply: