Ayuda para draggear matlab
Publicado por ivan (24 intervenciones) el 20/08/2012 13:41:49
Hola
Vereis estoy terminando mi proyecto final de carrera y he llegado a una parte un poco escabrosa, resulta que tengo un "axes" donde se muestra una señal de audio, y sobre esa señal de audio tengo que poder draggear, esto es que pueda seleccionar partes de la grafica y suprimirlas o moverlas a otro lado, para ello tengo este codigo:
function [P1 P2] = Posicion_Lineas(data)
Pos1=get(data.LineaMin, 'XData');
Pos2=get(data.LineaMax, 'XData');
if Pos1>Pos2
dum=Pos2;
Pos2=Pos1;
Pos1=dum;
end;
P1=floor(Pos1(1).*data.fs_original)+1;
P2=floor(Pos2(1).*data.fs_original)+1;
Y por otro lado tengo este otro:
function varargout = pitch_main(varargin)
% PITCH_MAIN M-file for pitch_main.fig
% PITCH_MAIN, by itself, creates a new PITCH_MAIN or raises the existing
% singleton*.
%
% H = PITCH_MAIN returns the handle to a new PITCH_MAIN or the handle to
% the existing singleton*.
%
% PITCH_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PITCH_MAIN.M with the given input arguments.
%
% PITCH_MAIN('Property','Value',...) creates a new PITCH_MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before pitch_main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to pitch_main_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 pitch_main
% Last Modified by GUIDE v2.5 06-Sep-2011 19:04:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @pitch_main_OpeningFcn, ...
'gui_OutputFcn', @pitch_main_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 pitch_main is made visible.
function pitch_main_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 pitch_main (see VARARGIN)
% Choose default command line output for pitch_main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
if strcmp(get(hObject,'Visible'),'off')
initialize_gui(hObject, handles);
end
% UIWAIT makes pitch_main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = pitch_main_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;
function initialize_gui(fig_handle, handles)
data.M=[];
data.indice_alg=1;%indice para el text box de algoritmo.
data.init=0; %para ver si ya se ha cargado algun archivo
data.recalc_silencios=1;
data.silencios.te='auto';
data.hps.Armlimit=0.01; %limite para HPS
datahps.ceps=0;
data.hps.Armax=0;
data.hps.whit=1;
% data.solape=50;
% data.N=1024;
setappdata(fig_handle, 'data', data);
%
% set(handles.edit9, 'String', data.L);
% set(handles.edit11, 'String', data.solape);
% set(handles.edit27, 'String', data.N);
function edit_nombre_wav_Callback(hObject, eventdata, handles)
% hObject handle to edit_nombre_wav (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 edit_nombre_wav as text
% str2double(get(hObject,'String')) returns contents of edit_nombre_wav as a double
% --- Executes during object creation, after setting all properties.
function edit_nombre_wav_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_nombre_wav (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 button press in Boton_Cargar.
function Boton_Cargar_Callback(hObject, eventdata, handles)
% hObject handle to Boton_Cargar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data = getappdata(gcbf, 'data');
if data.init==1
PathName=data.PathName;
[FileName, PathName, filterindex] = uigetfile( {'*.wav', 'Archivo PCM WAV(*.wav)';'*.aiff', 'Archivo AIFF(*.aiff)'; ...
'*.au','Archivo AU(*.au)';'*.*', 'Todos los Archivos(*.*)'},'Selecciona un archivo de audio',PathName);
else
[FileName, PathName, filterindex] = uigetfile( {'*.wav', 'Archivo PCM WAV(*.wav)';'*.aiff', 'Archivo AIFF(*.aiff)'; ...
'*.au','Archivo AU(*.au)';'*.*', 'Todos los Archivos(*.*)'},'Selecciona un archivo de audio');
end;
if ~isequal(FileName,0) && ~isequal(PathName,0) %SI SE HA ELEGIDO UN ARCHIVO VáLIDO....
% close(Configurar_Silencios);
% close(Configurar_Analisis_Espectrograma);
% close all;
data.init=1;
data.recalc_silencios=1;
data.PathName=PathName;
[PATHSTR,NAME,EXT,VERSN] = fileparts([PathName FileName]);
switch lower(EXT)
case '.wav'
[x,fs,nbits]=wavread([PathName FileName]);
case '.aiff'
[x,fs,nbits]=aiffread([PathName FileName]);
x=x./32768;
nbits=max(nbits);
case '.au'
[x,fs,nbits]=auread([PathName FileName]);
otherwise
errordlg('Formato no soportado','Error');
return;
end;
siz=size(x);
if siz(2)==2
x=sum(x,2)./2;
end;
%Parte de datos
% data = getappdata(gcbf, 'data');
%Configuración de la señal
data.x=x;
data.fs_original=fs;
data.fs=fs;
data.nbits=nbits;
%Configuración de la ventana
data.L=fix((1024/44100)*fs);
data.Lseg=data.L/fs;
data.Solape=50;
data.w=hamming(data.L);
data.Solape_M=floor((1-(data.Solape/100))*data.L);
set(handles.edit_VENTANA_L, 'Enable', 'off');
set(handles.edit_VENTANA_L, 'String', data.L);
set(handles.edit_VENTANA_Lseg, 'Enable', 'off');
set(handles.edit_VENTANA_Lseg, 'String', fix(data.L/fs*100000)/100);
set(handles.edit_VENTANA_SOLAPE, 'Enable', 'on');
set(handles.edit_VENTANA_SOLAPE, 'String', data.Solape);
set(handles.popupmenu_VENTANA_TIPO, 'Enable', 'on');
set(handles.popup_VENTANA_LSEG, 'Enable', 'on');
%Configuración de algoritmos de Estimación de pitch
data.fmin=50;
data.fmax=2000;
if data.fmax>data.fs/2
data.fmax=data.fs/2;
end;
set(handles.edit_fmin, 'Enable', 'on');
set(handles.edit_fmax, 'Enable', 'on');
set(handles.edit_fmin, 'String', data.fmin);
set(handles.edit_fmax, 'String', data.fmax);
set(handles.Boton_Algoritmo_Analisis, 'Enable', 'on');
set(handles.popupmenu_Algoritmo_Tipo, 'Enable', 'on');
set(handles.Boton_Ejecutar_Transcripccion, 'Enable', 'on');
%INICIALIZACION DE ALGORITMOS
%HPS
data.hps.Armlimit=0.01; %limite para HPS
data.hps.ceps=0;
data.hps.Armax=0;
data.hps.whit=1;
%CONFIGURACION DE ESPECTROGRAMA
data.espectrograma.N=fix((1024/44100)*fs);
data.espectrograma.L=fix(((1024/44100)*fs)/2);
data.espectrograma.solape=50;
set(handles.edit_nombre_wav, 'String', FileName);
data.filename=FileName;
set(handles.edit_FS, 'String', fs);
%set(handles.edit_FS, 'Enable', 'on');
set(handles.Boton_Reproducir, 'Enable', 'on');
set(handles.Boton_Salvar, 'Enable', 'on');
set(handles.Boton_Analisis, 'Enable', 'on');
set(handles.popupmenu_Analisis, 'Enable', 'on');
set(handles.Toggle_Silencios, 'Enable', 'on');
set(handles.Toggle_Silencios, 'String', 'Activar');
set(handles.Toggle_Silencios, 'Value',0);
set(handles.Boton_Configurar_Silencios, 'Enable', 'off');
set(handles.Boton_Ejecutar_Transcripccion, 'Enable', 'on');
set(handles.Boton_Configurar_Transcripcion, 'Enable', 'off');
%Configuracion de silencios
data.ite=floor((length(data.x))/(data.L-data.Solape_M+1));
data.silencios.silpos=ones(data.ite+1,1);
data.silencios.Cuadro=0;
data.silencios.LineaMin=0;
%Parte Gráfica
setappdata(gcbf, 'data', data);
plot_axes1(data,handles);
end;
ESTE CODIGO ESTA INCOMPLETO, DEBIDO A QUE NO PUEDO PONERLO ENTERO AQUI, SI ALGUIEN ESTA INTERESADO QUE ME AVISE Y LE MANDO EL SCRIPT COMPLETO.
Estos codigos me los dieron de otro proyecto, con lo que en teoria se supone que deben de funcionar pero por mas que los pruebo no consigo nada, si alguien sabe otra forma de dragear...
Saludos y gracias
Vereis estoy terminando mi proyecto final de carrera y he llegado a una parte un poco escabrosa, resulta que tengo un "axes" donde se muestra una señal de audio, y sobre esa señal de audio tengo que poder draggear, esto es que pueda seleccionar partes de la grafica y suprimirlas o moverlas a otro lado, para ello tengo este codigo:
function [P1 P2] = Posicion_Lineas(data)
Pos1=get(data.LineaMin, 'XData');
Pos2=get(data.LineaMax, 'XData');
if Pos1>Pos2
dum=Pos2;
Pos2=Pos1;
Pos1=dum;
end;
P1=floor(Pos1(1).*data.fs_original)+1;
P2=floor(Pos2(1).*data.fs_original)+1;
Y por otro lado tengo este otro:
function varargout = pitch_main(varargin)
% PITCH_MAIN M-file for pitch_main.fig
% PITCH_MAIN, by itself, creates a new PITCH_MAIN or raises the existing
% singleton*.
%
% H = PITCH_MAIN returns the handle to a new PITCH_MAIN or the handle to
% the existing singleton*.
%
% PITCH_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in PITCH_MAIN.M with the given input arguments.
%
% PITCH_MAIN('Property','Value',...) creates a new PITCH_MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before pitch_main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to pitch_main_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 pitch_main
% Last Modified by GUIDE v2.5 06-Sep-2011 19:04:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @pitch_main_OpeningFcn, ...
'gui_OutputFcn', @pitch_main_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 pitch_main is made visible.
function pitch_main_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 pitch_main (see VARARGIN)
% Choose default command line output for pitch_main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
if strcmp(get(hObject,'Visible'),'off')
initialize_gui(hObject, handles);
end
% UIWAIT makes pitch_main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = pitch_main_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;
function initialize_gui(fig_handle, handles)
data.M=[];
data.indice_alg=1;%indice para el text box de algoritmo.
data.init=0; %para ver si ya se ha cargado algun archivo
data.recalc_silencios=1;
data.silencios.te='auto';
data.hps.Armlimit=0.01; %limite para HPS
datahps.ceps=0;
data.hps.Armax=0;
data.hps.whit=1;
% data.solape=50;
% data.N=1024;
setappdata(fig_handle, 'data', data);
%
% set(handles.edit9, 'String', data.L);
% set(handles.edit11, 'String', data.solape);
% set(handles.edit27, 'String', data.N);
function edit_nombre_wav_Callback(hObject, eventdata, handles)
% hObject handle to edit_nombre_wav (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 edit_nombre_wav as text
% str2double(get(hObject,'String')) returns contents of edit_nombre_wav as a double
% --- Executes during object creation, after setting all properties.
function edit_nombre_wav_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit_nombre_wav (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 button press in Boton_Cargar.
function Boton_Cargar_Callback(hObject, eventdata, handles)
% hObject handle to Boton_Cargar (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data = getappdata(gcbf, 'data');
if data.init==1
PathName=data.PathName;
[FileName, PathName, filterindex] = uigetfile( {'*.wav', 'Archivo PCM WAV(*.wav)';'*.aiff', 'Archivo AIFF(*.aiff)'; ...
'*.au','Archivo AU(*.au)';'*.*', 'Todos los Archivos(*.*)'},'Selecciona un archivo de audio',PathName);
else
[FileName, PathName, filterindex] = uigetfile( {'*.wav', 'Archivo PCM WAV(*.wav)';'*.aiff', 'Archivo AIFF(*.aiff)'; ...
'*.au','Archivo AU(*.au)';'*.*', 'Todos los Archivos(*.*)'},'Selecciona un archivo de audio');
end;
if ~isequal(FileName,0) && ~isequal(PathName,0) %SI SE HA ELEGIDO UN ARCHIVO VáLIDO....
% close(Configurar_Silencios);
% close(Configurar_Analisis_Espectrograma);
% close all;
data.init=1;
data.recalc_silencios=1;
data.PathName=PathName;
[PATHSTR,NAME,EXT,VERSN] = fileparts([PathName FileName]);
switch lower(EXT)
case '.wav'
[x,fs,nbits]=wavread([PathName FileName]);
case '.aiff'
[x,fs,nbits]=aiffread([PathName FileName]);
x=x./32768;
nbits=max(nbits);
case '.au'
[x,fs,nbits]=auread([PathName FileName]);
otherwise
errordlg('Formato no soportado','Error');
return;
end;
siz=size(x);
if siz(2)==2
x=sum(x,2)./2;
end;
%Parte de datos
% data = getappdata(gcbf, 'data');
%Configuración de la señal
data.x=x;
data.fs_original=fs;
data.fs=fs;
data.nbits=nbits;
%Configuración de la ventana
data.L=fix((1024/44100)*fs);
data.Lseg=data.L/fs;
data.Solape=50;
data.w=hamming(data.L);
data.Solape_M=floor((1-(data.Solape/100))*data.L);
set(handles.edit_VENTANA_L, 'Enable', 'off');
set(handles.edit_VENTANA_L, 'String', data.L);
set(handles.edit_VENTANA_Lseg, 'Enable', 'off');
set(handles.edit_VENTANA_Lseg, 'String', fix(data.L/fs*100000)/100);
set(handles.edit_VENTANA_SOLAPE, 'Enable', 'on');
set(handles.edit_VENTANA_SOLAPE, 'String', data.Solape);
set(handles.popupmenu_VENTANA_TIPO, 'Enable', 'on');
set(handles.popup_VENTANA_LSEG, 'Enable', 'on');
%Configuración de algoritmos de Estimación de pitch
data.fmin=50;
data.fmax=2000;
if data.fmax>data.fs/2
data.fmax=data.fs/2;
end;
set(handles.edit_fmin, 'Enable', 'on');
set(handles.edit_fmax, 'Enable', 'on');
set(handles.edit_fmin, 'String', data.fmin);
set(handles.edit_fmax, 'String', data.fmax);
set(handles.Boton_Algoritmo_Analisis, 'Enable', 'on');
set(handles.popupmenu_Algoritmo_Tipo, 'Enable', 'on');
set(handles.Boton_Ejecutar_Transcripccion, 'Enable', 'on');
%INICIALIZACION DE ALGORITMOS
%HPS
data.hps.Armlimit=0.01; %limite para HPS
data.hps.ceps=0;
data.hps.Armax=0;
data.hps.whit=1;
%CONFIGURACION DE ESPECTROGRAMA
data.espectrograma.N=fix((1024/44100)*fs);
data.espectrograma.L=fix(((1024/44100)*fs)/2);
data.espectrograma.solape=50;
set(handles.edit_nombre_wav, 'String', FileName);
data.filename=FileName;
set(handles.edit_FS, 'String', fs);
%set(handles.edit_FS, 'Enable', 'on');
set(handles.Boton_Reproducir, 'Enable', 'on');
set(handles.Boton_Salvar, 'Enable', 'on');
set(handles.Boton_Analisis, 'Enable', 'on');
set(handles.popupmenu_Analisis, 'Enable', 'on');
set(handles.Toggle_Silencios, 'Enable', 'on');
set(handles.Toggle_Silencios, 'String', 'Activar');
set(handles.Toggle_Silencios, 'Value',0);
set(handles.Boton_Configurar_Silencios, 'Enable', 'off');
set(handles.Boton_Ejecutar_Transcripccion, 'Enable', 'on');
set(handles.Boton_Configurar_Transcripcion, 'Enable', 'off');
%Configuracion de silencios
data.ite=floor((length(data.x))/(data.L-data.Solape_M+1));
data.silencios.silpos=ones(data.ite+1,1);
data.silencios.Cuadro=0;
data.silencios.LineaMin=0;
%Parte Gráfica
setappdata(gcbf, 'data', data);
plot_axes1(data,handles);
end;
ESTE CODIGO ESTA INCOMPLETO, DEBIDO A QUE NO PUEDO PONERLO ENTERO AQUI, SI ALGUIEN ESTA INTERESADO QUE ME AVISE Y LE MANDO EL SCRIPT COMPLETO.
Estos codigos me los dieron de otro proyecto, con lo que en teoria se supone que deben de funcionar pero por mas que los pruebo no consigo nada, si alguien sabe otra forma de dragear...
Saludos y gracias
Valora esta pregunta


0