Sediment Transport Matlab Code

Embed Size (px)

DESCRIPTION

programación desde matlab para el transprote de sediementos

Citation preview

  • 7/13/14 11:44 AM D:\SedimentTransport.m 1 of 7

    function varargout = SedimentTransport(varargin)% SEDIMENTTRANSPORT MATLAB code for SedimentTransport.fig% SEDIMENTTRANSPORT, by itself, creates a new SEDIMENTTRANSPORT or raises theexisting% singleton*.%% H = SEDIMENTTRANSPORT returns the handle to a new SEDIMENTTRANSPORT or the handleto% the existing singleton*.%% SEDIMENTTRANSPORT('CALLBACK',hObject,eventData,handles,...) calls the local% function named CALLBACK in SEDIMENTTRANSPORT.M with the given input arguments.%% SEDIMENTTRANSPORT('Property','Value',...) creates a new SEDIMENTTRANSPORT orraises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI before SedimentTransport_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to SedimentTransport_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 SedimentTransport

    % Last Modified by GUIDE v2.5 10-Jul-2014 09:08:50

    % Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, ...

    'gui_Singleton', gui_Singleton, ...'gui_OpeningFcn', @SedimentTransport_OpeningFcn, ...'gui_OutputFcn', @SedimentTransport_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

    % --- Executes just before SedimentTransport is made visible.function SedimentTransport_OpeningFcn(hObject, eventdata, handles, varargin)

  • 7/13/14 11:44 AM D:\SedimentTransport.m 2 of 7

    % 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 SedimentTransport (see VARARGIN)

    % Choose default command line output for SedimentTransporthandles.output = hObject;

    % Update handles structureguidata(hObject, handles);

    % UIWAIT makes SedimentTransport wait for user response (see UIRESUME)% uiwait(handles.figure1);

    % --- Outputs from this function are returned to the command line.function varargout = SedimentTransport_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 structurevarargout{1} = handles.output;

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% MENU ARCHIVO %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % --------------------------------------------------------------------function Archivo_Callback(hObject, eventdata, handles)% hObject handle to Archivo (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    % --------------------------------------------------------------------function Nuevo_Callback(hObject, eventdata, handles)% hObject handle to Nuevo (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    % --------------------------------------------------------------------function Abrir_Callback(hObject, eventdata, handles)% hObject handle to Abrir (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

  • 7/13/14 11:44 AM D:\SedimentTransport.m 3 of 7

    LeerDatos(handles);

    % --------------------------------------------------------------------function Guardar_Callback(hObject, eventdata, handles)% hObject handle to Guardar (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    % --------------------------------------------------------------------function GuardarComo_Callback(hObject, eventdata, handles)% hObject handle to GuardarComo (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    % --------------------------------------------------------------------function Salir_Callback(hObject, eventdata, handles)% hObject handle to Salir (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% CONTROLES ADICIONALES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    % --- Executes on selection change in popupmenu1.function popupmenu1_Callback(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu1 contents as cellarray% contents{get(hObject,'Value')} returns selected item from popupmenu1

    global P X H Cr Cl% La progresiva seleccionada en el control popupmenu1k=get(handles.popupmenu1,'Value');%yy=get(hObject,'Value')% Las ordenadas (H) para la progresiva seleccionadah=H(:,k);% Graficarset(handles.axes1,'NextPlot', 'Replace');plot(X,h,'-o');title(strcat('Progresiva: ', num2str(P(k))));

  • 7/13/14 11:44 AM D:\SedimentTransport.m 4 of 7

    axis normal;grid on;% Coeficientes de manningset(handles.edit1,'String',Cl(k));set(handles.edit2,'String',Cr(k));

    % --- Executes during object creation, after setting all properties.function popupmenu1_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called

    % Hint: popupmenu 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

    function edit1_Callback(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    % Hints: get(hObject,'String') returns contents of edit1 as text% str2double(get(hObject,'String')) returns contents of edit1 as a double

    % --- Executes during object creation, after setting all properties.function edit1_CreateFcn(hObject, eventdata, handles)% hObject handle to edit1 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called

    % Hint: edit 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

    function edit2_Callback(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

  • 7/13/14 11:44 AM D:\SedimentTransport.m 5 of 7

    % Hints: get(hObject,'String') returns contents of edit2 as text% str2double(get(hObject,'String')) returns contents of edit2 as a double

    % --- Executes during object creation, after setting all properties.function edit2_CreateFcn(hObject, eventdata, handles)% hObject handle to edit2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called

    % Hint: edit 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

    % --- Executes on selection change in popupmenu2.function popupmenu2_Callback(hObject, eventdata, handles)% hObject handle to popupmenu2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)

    % Hints: contents = cellstr(get(hObject,'String')) returns popupmenu2 contents as cellarray% contents{get(hObject,'Value')} returns selected item from popupmenu2global Tr D Qh% La progresiva seleccionada en el control popupmenu1k=get(handles.popupmenu2,'Value');%yy=get(hObject,'Value')% Los caudales para el Tr seleccionadoq=Qh(:,k);% Graficarset(handles.axes1,'NextPlot', 'Replace');plot(D,q,'-o');title(strcat('Tiempo de Retorno: ', num2str(Tr(k))));axis normal;grid on;% Coeficientes de manning%set(handles.edit1,'String',Cl(k));%set(handles.edit2,'String',Cr(k));

    % --- Executes during object creation, after setting all properties.function popupmenu2_CreateFcn(hObject, eventdata, handles)% hObject handle to popupmenu2 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB

  • 7/13/14 11:44 AM D:\SedimentTransport.m 6 of 7

    % handles empty - handles not created until after all CreateFcns called

    % Hint: popupmenu 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

    %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% FUNCTIONS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

    function LeerDatos(handles)% Variables Globalesglobal P X H Cr Cl Tr D Qh% Lectura de la direccin y nombre del archivo excel[filename, pathname] = ... uigetfile({...

    '*.xlsx','Microsoft Excel Files (*.xlsx)' ;...'*.xls','Microsoft Excel Files (*.xls)' ;...'*.*', 'All Files (*.*)'},...'File Selector');

    % Verificar si un archivo fue seleccionadoif filename ~= 0

    % Direccin completa al archivo selecionado direccion=strcat(pathname, filename);

    % Hoja 1% Lectura de los datos del archivo excel

    num = xlsread(direccion,1); [m,n]=size(num);

    % P: Progresivas, X: distancia izquierda derecha, H: alturas,% Coeficiente de manning: Cr Cl

    P=num(1,2:n); % Progresiva Cr=num(2,2:n); % C margen derecho Cl=num(3,2:n); % C margen izquierdo X=num(6:m,1); H=num(6:m,2:n);

    % Carga las progresivas a un popupmenu1 b=mat2cell(P,1); set(handles.popupmenu1,'String',b);

    % Hoja 2% Lectura de los datos del archivo excel

    num = xlsread(direccion,2); [m,n]=size(num);

    % Tr: tiempo de retorno, D: duracin(horas), Qh: caudales del% hidrograma

  • 7/13/14 11:44 AM D:\SedimentTransport.m 7 of 7

    Tr=num(1,2:n); D=num(2:m,1); Qh=num(2:m,2:n);

    % Carga las progresivas a un popupmenu2 b=mat2cell(Tr,1); set(handles.popupmenu2,'String',b);

    end

    function A=CoordinateSurface(M)% Function description% Input: M is array m*n, coordinates polygon% Output: A surface polygon% Aadiendo la primera coordenada al finalM=[M;M(1,:)];% Tamao de la matriz[m,n]=size(M);% VariablesA=0; D=0; I=0;% Clculo de la superficiefor k=1:(m-1)

    % Valores D d1=M(k,1); d2=M(k+1,2); D=D+d1*d2;

    % valores I i1=M(k,2); i2=M(k+1,1); I=I+i1*i2;end% La superficie valor de retornoA=1/2*abs(D-I);