Verfasst am: 06.10.2018, 14:42
Titel: komisches Verhalten der GUI
Hallo, bei folgendem Szenarion verhält sich meine GUI sehr merkwürdig:
Wenn man einen Slider verstellt z.b. einen von bk dann verändert sich der plot wie gewünscht . Wenn ich danach einen anderen Slider von bk oder ak verstelle ist auch alles in ordnung. Wenn ich nun einen dieser beiden gerade verstellten slider auf den wert null stelle geht eine gerade durch null. Was ja eigentlich nicht sein kann denn einen der beiden ak oder bk wie auch immer hat ja immernoch einen wert größer null und es müsste eine periodische funktion zu sehen sein im plot.
Woran könnte das liegen?
Hier der Code:
Code:
functionvarargout = fourier_synthi(varargin) % FOURIER_SYNTHI MATLAB code for fourier_synthi.fig % FOURIER_SYNTHI, by itself, creates a new FOURIER_SYNTHI or raises the existing % singleton*.
%
% H = FOURIER_SYNTHI returns the handle to a new FOURIER_SYNTHI or the handle to % the existing singleton*.
%
% FOURIER_SYNTHI('CALLBACK',hObject,eventData,handles,...) calls the local % function named CALLBACK in FOURIER_SYNTHI.M with the given input arguments.
%
% FOURIER_SYNTHI('Property','Value',...) creates a new FOURIER_SYNTHI or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before fourier_synthi_OpeningFcn gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to fourier_synthi_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 fourier_synthi
% Last Modified by GUIDE v2.5 06-Oct-2018 15:16:45
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @fourier_synthi_OpeningFcn, ...
'gui_OutputFcn', @fourier_synthi_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
ifnargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
% --- Executes just before fourier_synthi is made visible. function fourier_synthi_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 fourier_synthi (see VARARGIN)
% Choose default command line output for fourier_synthi
handles.output = hObject;
% UIWAIT makes fourier_synthi wait for user response (see UIRESUME) % uiwait(handles.figure1);
ak = [get(handles.slider1,'value');get(handles.slider2,'value');get(handles.slider3,'value');
get(handles.slider4,'value');get(handles.slider5,'value');get(handles.slider6,'value')];
handles.ak = ak;
bk = [0;get(handles.slider8,'value');get(handles.slider9,'value');get(handles.slider10,'value');
get(handles.slider11,'value');get(handles.slider12,'value')];
handles.bk = bk;
% --- Outputs from this function are returned to the command line. functionvarargout = fourier_synthi_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 pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) % hObject handle to pushbutton1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
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
N = str2double(get(handles.edit1,'string'));
if N == round(N) && N > 10
M = int16(N);
set(handles.edit1,'string',num2str(M));
else set(handles.edit1,'string','1000');
end
handles.N = str2num(get(handles.edit1,'string'));
fouriersynthi = fouriersynthese(handles.N,handles.ak,handles.bk);
% --- 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. ifispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white');
end
% --- Executes on slider movement. function slider8_Callback(hObject, eventdata, handles) % hObject handle to slider8 (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.bk(2) = get(handles.slider8,'value');
fouriersynthi = fouriersynthese(handles.N,handles.ak,handles.bk);
% --- Executes during object creation, after setting all properties. function slider8_CreateFcn(hObject, eventdata, handles) % hObject handle to slider8 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background. ifisequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement. function slider9_Callback(hObject, eventdata, handles) % hObject handle to slider9 (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.bk(3) = get(handles.slider9,'value');
fouriersynthi = fouriersynthese(handles.N,handles.ak,handles.bk);
% --- Executes during object creation, after setting all properties. function slider9_CreateFcn(hObject, eventdata, handles) % hObject handle to slider9 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background. ifisequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement. function slider10_Callback(hObject, eventdata, handles) % hObject handle to slider10 (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.bk(4) = get(handles.slider10,'value');
plot(fouriersynthi);
% --- Executes during object creation, after setting all properties. function slider10_CreateFcn(hObject, eventdata, handles) % hObject handle to slider10 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background. ifisequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement. function slider11_Callback(hObject, eventdata, handles) % hObject handle to slider11 (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.bk(5) = get(handles.slider11,'value');
% --- Executes during object creation, after setting all properties. function slider11_CreateFcn(hObject, eventdata, handles) % hObject handle to slider11 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background. ifisequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement. function slider12_Callback(hObject, eventdata, handles) % hObject handle to slider12 (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.bk(6) = get(handles.slider12,'value');
% --- Executes during object creation, after setting all properties. function slider12_CreateFcn(hObject, eventdata, handles) % hObject handle to slider12 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background. ifisequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement. function slider1_Callback(hObject, eventdata, handles) % hObject handle to slider1 (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.ak(1) = get(handles.slider1,'value');
% --- Executes during object creation, after setting all properties. function slider1_CreateFcn(hObject, eventdata, handles) % hObject handle to slider1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background. ifisequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement. function slider2_Callback(hObject, eventdata, handles) % hObject handle to slider2 (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.ak(2) = get(handles.slider2,'value');
% --- Executes during object creation, after setting all properties. function slider2_CreateFcn(hObject, eventdata, handles) % hObject handle to slider2 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background. ifisequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement. function slider3_Callback(hObject, eventdata, handles) % hObject handle to slider3 (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.ak(3) = get(handles.slider3,'value');
% --- Executes during object creation, after setting all properties. function slider3_CreateFcn(hObject, eventdata, handles) % hObject handle to slider3 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background. ifisequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement. function slider4_Callback(hObject, eventdata, handles) % hObject handle to slider4 (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.ak(4) = get(handles.slider4,'value');
% --- Executes during object creation, after setting all properties. function slider4_CreateFcn(hObject, eventdata, handles) % hObject handle to slider4 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background. ifisequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement. function slider5_Callback(hObject, eventdata, handles) % hObject handle to slider5 (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.ak(5) = get(handles.slider5,'value');
% --- Executes during object creation, after setting all properties. function slider5_CreateFcn(hObject, eventdata, handles) % hObject handle to slider5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background. ifisequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement. function slider6_Callback(hObject, eventdata, handles) % hObject handle to slider6 (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,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider
handles.ak(6) = get(handles.slider6,'value');
% --- Executes during object creation, after setting all properties. function slider6_CreateFcn(hObject, eventdata, handles) % hObject handle to slider6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background. ifisequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on mouse press over axes background. function axes1_ButtonDownFcn(hObject, eventdata, handles) % hObject handle to axes1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties. function axes1_CreateFcn(hObject, eventdata, handles) % hObject handle to axes1 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called
% Hint: place code in OpeningFcn to populate axes1
Empfehlung: erst mal versuchen, anhand zwei statt zwölf Slidern ein Verständnis für das ganze entwickeln. So ist das für andere recht unübersichtlich und schwer zu erahnen, um was es gerade genau geht.
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 ;)
Verfasst am: 06.10.2018, 14:55
Titel: komisches Verhalten der GUI
genau das habe ich in jeder slider fct eben eingefügt und es funktionierte.
Danke
Einstellungen und Berechtigungen
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
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.