MATLAB: Help for batch selection in graphical window

arrayguipathselection fileswindow

Hi to all…
I wrote:
function varargout = finestra(varargin)
% FINESTRA M-file for finestra.fig
% FINESTRA, by itself, creates a new FINESTRA or raises the existing
% singleton*.
%




% H = FINESTRA returns the handle to a new FINESTRA or the handle to
% the existing singleton*.
%
% FINESTRA('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in FINESTRA.M with the given input arguments.
%
% FINESTRA('Property','Value',...) creates a new FINESTRA or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before finestra_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to finestra_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help finestra
% Last Modified by GUIDE v2.5 26-Jun-2011 17:43:19
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @finestra_OpeningFcn, ...
'gui_OutputFcn', @finestra_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
%*************************************************************************







%finestra
%*************************************************************************
% --- Executes just before finestra is made visible.
function finestra_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure

% eventdata reserved - to be defined in a future version of MATLAB







% handles structure with handles and user data (see GUIDATA)





% varargin command line arguments to finestra (see VARARGIN)
% Choose default command line output for finestra
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes finestra wait for user response (see UIRESUME)
% uiwait(handles.finestra);
if nargin == 3,
initial_dir = pwd;
elseif nargin > 4
if strcmpi(varargin{1},'dir')
if exist(varargin{2},'dir')
initial_dir = varargin{2};
else
errordlg('Input argument must be a valid directory','Input Argument Error!')
return
end
else
errordlg('Unrecognized input argument','Input Argument Error!');
return;
end
end
% Populate the listbox
load_CercaFile(initial_dir,handles)
% --- Executes during object creation, after setting all properties.

function finestra_CreateFcn(hObject, eventdata, handles)
% hObject handle to finestra (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

setappdata(hObject, 'StartPath', pwd);
addpath(pwd);
% --- Executes during object deletion, before destroying properties.
function finestra_DeleteFcn(hObject, eventdata, handles)
% hObject handle to finestra (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isappdata(hObject, 'StartPath')
rmpath(getappdata(hObject, 'StartPath'));
end
% --- Outputs from this function are returned to the command line.
function varargout = finestra_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
%*************************************************************************
%OK
%*************************************************************************
% --- Executes on button press in OK.
function OK_Callback(hObject, eventdata, handles)
% hObject handle to OK (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%*************************************************************************
%Annulla
%*************************************************************************
% --- Executes on button press in Annulla.
function Annulla_Callback(hObject, eventdata, handles)
% hObject handle to Annulla (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%*************************************************************************
%Lista
%*************************************************************************
% --- Executes on selection change in CercaFile.
function CercaFile_Callback(hObject, eventdata, handles)
% hObject handle to CercaFile (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: contents = get(hObject,'String') returns CercaFile contents as cell array
% contents{get(hObject,'Value')} returns selected item from CercaFile
get(handles.finestra,'SelectionType');
if strcmp(get(handles.finestra,'SelectionType'),'open')
index_selected = get(handles.CercaFile,'Value');
file_list = get(handles.CercaFile,'String');
filename = file_list{index_selected};
if handles.is_dir(handles.sorted_index(index_selected))
cd (filename)
load_CercaFile(pwd,handles)
else
[path,name,ext,ver] = fileparts(filename);
switch ext
case '.fig'
guide (filename)
otherwise
try
open(filename)
catch
errordlg(lasterr,'File Type Error','modal')
end
end
end
end
% ------------------------------------------------------------

% Read the current directory and sort the names
% ------------------------------------------------------------
function load_CercaFile(dir_path,handles)
cd (dir_path)
dir_struct = dir(dir_path);
[sorted_names,sorted_index] = sortrows({dir_struct.name}');
handles.file_names = sorted_names;
handles.is_dir = [dir_struct.isdir];
handles.sorted_index = sorted_index;
guidata(handles.finestra,handles)
set(handles.CercaFile,'String',handles.file_names,'Value',1)
set(handles.PathIn,'String',pwd)
% --- Executes during object creation, after setting all properties.
function CercaFile_CreateFcn(hObject, eventdata, handles)
% hObject handle to CercaFile (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: listbox controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
**************************************************************** ****************************************************************
now i navigate in file system displayed in the window, i need to select one or more files (once), and insert their path in an array…
how can i do that???
thanks…

Best Answer

There is information missing from this, such as what the object type and Style for CercaFile is, and the certainty that CercaFile_Callback is the callback for that object.
If we presume a listbox and presume that CercaFile_Callback is indeed its callback, then edit CercaFile_Callback so that instead of invoking guide() or open() on the chosen file, it records the file name in which-ever location is convenient for you.
Related Question