how can i call two push buttons from the 3rd push button in GUI without disabling any pushbuttons?
3 次查看(过去 30 天)
显示 更早的评论
this is my code. when i press signal1_pushbutton--> output signal will appear. similarly,signal2_pushbutton. now i wan to stop the signal by using stop push button.
these are the conditions, i want to satisfy:-
1.press signal1---stops the signal by using stop button.
2.lly, signal2.
3.But when i press signal2 after signal1, the stop button shoulde be able(on) state, but it wont respond!!!
how can i do that? suggestions are appreciated!
function varargout = trail1(varargin)
% TRAIL1 MATLAB code for trail1.fig
% TRAIL1, by itself, creates a new TRAIL1 or raises the existing
% singleton*.
%
% H = TRAIL1 returns the handle to a new TRAIL1 or the handle to
% the existing singleton*.
%
% TRAIL1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in TRAIL1.M with the given input arguments.
%
% TRAIL1('Property','Value',...) creates a new TRAIL1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before trail1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to trail1_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 trail1
% Last Modified by GUIDE v2.5 11-Feb-2018 16:17:00
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @trail1_OpeningFcn, ...
'gui_OutputFcn', @trail1_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 trail1 is made visible.
function trail1_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 trail1 (see VARARGIN)
% Choose default command line output for trail1
handles.output = hObject;
% Indicate that neither pushbutton has been clicked yet:
handles.start_pushbutton = 0;
handles.attack_pushbutton = 0;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes trail1 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = trail1_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 start_pushbutton.
function signal1_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to start_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
evalin('base','sim(''testgui'')')
timeData = evalin('base','ScopeData1.time');
signalData = evalin('base','ScopeData1.signals.values');
curve = animatedline;
axis([0 100 -1 1]);------------- % if it is possible i want to get moving axis????
set(gca,'XLim',[0 1000],'YLim',[-1 1]);
grid on;
for i = 1:length(timeData)
addpoints(curve, timeData(i), signalData(i));
%drawnow;
end
handles.start_pushbutton = 1;
handles.attack_pushbutton = 0;
guidata(hObject, handles); %updates the handles
% --- Executes on button press in attack_pushbutton.
function signal2_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to attack_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
#######same as above code##### but different signal values#######
handles.start_pushbutton = 0;
handles.attack_pushbutton = 1;
% --- Executes on button press in stop_pushbutton.
function stop_pushbutton_Callback(hObject, eventdata, handles)
% hObject handle to stop_pushbutton (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%set_param('testgui','SimulationCommand','stop');
if (handles.start_pushbutton==1 && handles.attack_pushbutton==0)
disp('Fist Button was pressed.');
set_param('testgui','SimulationCommand','stop');
elseif (handles.start_pushbutton==0 && handles.attack_pushbutton==1)
disp('stop_pushbutton Button was pressed.');
set_param('testgui','SimulationCommand','stop');
elseif(handles.start_pushbutton==1 && handles.attack_pushbutton==1)
disp('all Button are pressed.');
set_param('testgui','SimulationCommand','not respond');
end
%if (handles.start_pushbutton==1)
% disp('Fist Button was pressed.');
% set_param('testgui','SimulationCommand','stop');
%elseif (handles.attack_pushbutton==1)
% disp('stop_pushbutton Button was pressed.');
% set_param('testgui','SimulationCommand','stop');
%elseif(handles.start_pushbutton==1 || handles.attack_pushbutton==1)
% disp('all Button are pressed.');
% set_param('testgui','SimulationCommand','not respond');
%end
but stop is not working as i want??? any suggestions please!!
3 个评论
Jan
2018-2-20
编辑:Jan
2018-2-20
Please explain "is not working as i want" with details. We cannot guess, what you want and what you observe. Providing details is much better than a meaningless bumping by a dummy comment or by adding comments to other questions to advertise your own one.
What exactly does "stops the signal" mean?
采纳的回答
Image Analyst
2018-2-20
See attached demo where you can use the pushbutton to start or stop a process.
8 个评论
Image Analyst
2018-2-20
Can you attach the .fig file and .m file and any other files necessary to run it and then tell me what I have to do to start and stop the process.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!