WICHTIG: Der Betrieb von goMatlab.de wird privat finanziert fortgesetzt. - Mehr Infos...

Mein MATLAB Forum - goMatlab.de

Mein MATLAB Forum

 
Gast > Registrieren       Autologin?   

Partner:




Forum
      Option
[Erweitert]
  • Diese Seite per Mail weiterempfehlen
     


Gehe zu:  
Neues Thema eröffnen Neue Antwort erstellen

GUI Break button

 

euglenagracilis
Forum-Newbie

Forum-Newbie


Beiträge: 2
Anmeldedatum: 16.05.19
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 20.05.2019, 16:23     Titel: GUI Break button
  Antworten mit Zitat      
Hallo, ich möchte eine GUI erstellen mit zwei Buttons. Einen damit die Funktion gestartet wird und den anderen dafür, dass die Funktion beendet wird.
Nun komme ich nicht mehr weiter und hoffe ihr könnt mir helfen. Ich habe mit GUIDE zwei Buttons erstellt:

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

% Last Modified by GUIDE v2.5 20-May-2019 15:48:22

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @guide_OpeningFcn, ...
                   'gui_OutputFcn',  @guide_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 guide is made visible.
function guide_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 guide (see VARARGIN)

% Choose default command line output for guide
handles.output = hObject;

% Zähler Initialisierung
handles.z = hObject;
handles.z = 0;

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = guide_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;


% --- Executes on button press in coloration1.
function coloration1_Callback(hObject, eventdata, handles)
% hObject    handle to coloration1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
p = 0.02;
outputFilePath = 'degraded.wav';
degType = "noi";

handles.z = 1;

% Update handles structure
guidata(hObject, handles);

realTimeDegradationFromMicrophone( degType, p, outputFilePath);

function realTimeDegradationFromMicrophone( degType, p, filePath)
audioReader = audioDeviceReader;

% frame length should be 20 ms
audioReader.SamplesPerFrame = round(audioReader.SampleRate * 0.02 );  

% file writer to save audio to .wav file
fileWriter = dsp.AudioFileWriter(filePath, 'SampleRate', audioReader.SampleRate);

% device writer to play audio to speakers
deviceWriter = audioDeviceWriter('SampleRate', audioReader.SampleRate);

%% Specify audio processing algorithm

switch degType
   
    case 'ref'
        process = @(x) x;
    case 'noi'
        process = @(x) x + p * randn(audioReader.SamplesPerFrame, 1);
    case 'dis'
        process = @(x) x .* (rand>p);
    case 'loud'
        process = @(x) x .* p;
    case 'col'
        mPEQ = multibandParametricEQ('HasLowpassFilter', true, 'LowpassCutoff', p);
        process = @(x) mPEQ(x);

end

%% Code for stream processing


while get(handles.z)=="1"
   
    guidata(hObject, handles);
    mySignal = audioReader();
    myProcessedSignal = process(mySignal);
   
    deviceWriter(myProcessedSignal);
    fileWriter(myProcessedSignal);
end

release(audioReader);
release(fileWriter);
release(deviceWriter);

% --- Executes on button press in coloration2.
function coloration2_Callback(hObject, eventdata, handles)
% hObject    handle to coloration2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

handles.z = 0;
guidata(hObject, handles);
 
Private Nachricht senden Benutzer-Profile anzeigen


Harald
Forum-Meister

Forum-Meister


Beiträge: 24.432
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 20.05.2019, 20:03     Titel:
  Antworten mit Zitat      
Hallo,

kannst du das Problem bzw. die Frage näher eingrenzen?
Dass du nicht weiterkommst, ist wenig aussagekräftig.

Grüße,
Harald
_________________

1.) Ask MATLAB Documentation
2.) Search gomatlab.de, google.de or MATLAB Answers
3.) Ask Technical Support of MathWorks
4.) Go mad, your problem is unsolvable ;)
Private Nachricht senden Benutzer-Profile anzeigen
 
euglenagracilis
Themenstarter

Forum-Newbie

Forum-Newbie


Beiträge: 2
Anmeldedatum: 16.05.19
Wohnort: ---
Version: ---
     Beitrag Verfasst am: 20.05.2019, 21:38     Titel:
  Antworten mit Zitat      
Hallo Harald,

dieser Teil des Codes:
Code:

% --- Executes on button press in coloration2.
function coloration2_Callback(hObject, eventdata, handles)
% hObject    handle to coloration2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

handles.z = 0;
guidata(hObject, handles);


wird nicht richtig ausgeführt, sodass:
Code:
while get(handles.z)=="1"
   
    guidata(hObject, handles);
    mySignal = audioReader();
    myProcessedSignal = process(mySignal);
   
    deviceWriter(myProcessedSignal);
    fileWriter(myProcessedSignal);
end

release(audioReader);
release(fileWriter);
release(deviceWriter);
 


mein z auf 1 bleibt und die Funktion nicht beendet wird.
Private Nachricht senden Benutzer-Profile anzeigen
 
Harald
Forum-Meister

Forum-Meister


Beiträge: 24.432
Anmeldedatum: 26.03.09
Wohnort: Nähe München
Version: ab 2017b
     Beitrag Verfasst am: 20.05.2019, 21:47     Titel:
  Antworten mit Zitat      
Hallo,

besser dürfte sein:
Code:
while get(handles.z)==1


Ich würde auch mal drawnow in die while-Schleife einfügen. Das sollte dazu führen, dass der andere Callback ausgeführt wird.

Grüße,
Harald
_________________

1.) Ask MATLAB Documentation
2.) Search gomatlab.de, google.de or MATLAB Answers
3.) Ask Technical Support of MathWorks
4.) Go mad, your problem is unsolvable ;)
Private Nachricht senden Benutzer-Profile anzeigen
 
Neues Thema eröffnen Neue Antwort erstellen



Einstellungen und Berechtigungen
Beiträge der letzten Zeit anzeigen:

Du kannst Beiträge in dieses Forum schreiben.
Du kannst auf Beiträge in diesem Forum antworten.
Du kannst deine Beiträge in diesem Forum nicht bearbeiten.
Du kannst deine Beiträge in diesem Forum nicht löschen.
Du kannst an Umfragen in diesem Forum nicht mitmachen.
Du kannst Dateien in diesem Forum posten
Du kannst Dateien in diesem Forum herunterladen
.





 Impressum  | Nutzungsbedingungen  | Datenschutz | FAQ | goMatlab RSS Button RSS

Hosted by:


Copyright © 2007 - 2024 goMatlab.de | Dies ist keine offizielle Website der Firma The Mathworks

MATLAB, Simulink, Stateflow, Handle Graphics, Real-Time Workshop, SimBiology, SimHydraulics, SimEvents, and xPC TargetBox are registered trademarks and The MathWorks, the L-shaped membrane logo, and Embedded MATLAB are trademarks of The MathWorks, Inc.