Home > Codi > Menu_Load_Dades.m

Menu_Load_Dades

PURPOSE ^

Pantalla per carregar objectes DATA des de fitxer al workspace. Permetem

SYNOPSIS ^

function varargout = Menu_Load_Dades(varargin)

DESCRIPTION ^

Pantalla per carregar objectes DATA des de fitxer al workspace. Permetem
diversos formats de fitxer (CSV, Mat)

Per invocar directament des de consola aquesta pantalla nomes cal
invocar-ne la funcio sense cap parametre extra:
Menu_Load_Dades();

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function varargout = Menu_Load_Dades(varargin)
0002 %Pantalla per carregar objectes DATA des de fitxer al workspace. Permetem
0003 %diversos formats de fitxer (CSV, Mat)
0004 %
0005 %Per invocar directament des de consola aquesta pantalla nomes cal
0006 %invocar-ne la funcio sense cap parametre extra:
0007 %Menu_Load_Dades();
0008 %
0009 
0010 gui_Singleton = 1;
0011 gui_State = struct('gui_Name',       mfilename, ...
0012                    'gui_Singleton',  gui_Singleton, ...
0013                    'gui_OpeningFcn', @Menu_Load_Dades_OpeningFcn, ...
0014                    'gui_OutputFcn',  @Menu_Load_Dades_OutputFcn, ...
0015                    'gui_LayoutFcn',  [], ...
0016                    'gui_Callback',   []);
0017 if nargin && ischar(varargin{1})
0018    gui_State.gui_Callback = str2func(varargin{1});
0019 end
0020 
0021 if nargout
0022     [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
0023 else
0024     gui_mainfcn(gui_State, varargin{:});
0025 end
0026 
0027 function Menu_Load_Dades_OpeningFcn(hObject, ~, handles, varargin)
0028 handles.output = hObject;
0029 guidata(hObject, handles);
0030 
0031 % --- S'executa en pulsar OK
0032 function OK_Callback(~, ~, handles)
0033 nom=get(handles.nom,'String');
0034 if isempty(nom)
0035     errordlg('A variable needs a name','Error');
0036 elseif str2double(nom(1))<10
0037     errordlg('A variable never starts with a number','Error');
0038 else
0039     nom = genvarname(nom);%passem el que hagi entrat l'usuari a nom valid de variable
0040     try
0041         if ~isempty(evalin('base',['whos( ''' nom ''' )'] ))
0042             choice = questdlg('this name is used, do you want to overwrite?', 'Attention', 'Yes','No','No');
0043             switch choice
0044                 case 'Yes'
0045                     %Sobreescriure
0046                     evalin('base',[ nom '=DATA();']);
0047                     format=get(handles.Format,'String');
0048                     format=format{get(handles.Format,'Value')};
0049                     fitxer=get(handles.Ruta,'String');
0050                     evalin('base',[ nom '.load(''' fitxer ''', ''' format ''');']);
0051                     
0052                     close('Menu_Load_Dades');
0053                     Update_Caller();
0054                     
0055                 case 'No'
0056                     %No fer res
0057                     
0058             end
0059         else
0060             
0061             evalin('base',[ nom '=DATA();']);
0062             format=get(handles.Format,'String');
0063             format=format{get(handles.Format,'Value')};
0064             fitxer=get(handles.Ruta,'String');
0065             evalin('base',[ nom '.load(''' fitxer ''', ''' format ''');']);
0066             
0067             close('Menu_Load_Dades');
0068             Update_Caller();
0069         end
0070     catch err
0071         errordlg(err.message,'Error');
0072     end
0073 end
0074 
0075 % --- S'executa en pulsar Selecciona
0076 function Selecciona_Callback(~, ~, handles)
0077 [FileName,PathName,~] = uigetfile('*.*');
0078 
0079 if FileName ==0 
0080  set(handles.Ruta,'String','No file selected');
0081 else
0082  set(handles.Ruta,'String',strcat(PathName,FileName));
0083 end
0084 
0085 %-----------------------------INUTILS--------------------------------------
0086 function varargout = Menu_Load_Dades_OutputFcn(~, ~, handles)
0087 varargout{1} = handles.output;
0088 function Format_Callback(~, ~, ~)
0089 function Format_CreateFcn(hObject, ~, ~)
0090 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0091     set(hObject,'BackgroundColor','white');
0092 end
0093 function nom_Callback(~, ~, ~)
0094 function nom_CreateFcn(hObject, ~, ~)
0095 if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
0096     set(hObject,'BackgroundColor','white');
0097 end

Generated on Wed 12-Sep-2012 13:03:54 by m2html © 2005