how to have a message that indicates me the experiment is done?

1 Ansicht (letzte 30 Tage)
Hello everyone,
İ would that when the ''Next button'' is done with the counter, it returns something like maybe a message saying that all the data have been used so the experiment is done.
Each time , i am clicking on the Next button, it is getting data from an excel file. İn another words, i am having 120 cases (drawing lines) in excel and i would like that after the 120 cases done , i should have a feedback that everything is done.
function franck_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 franck_guide (see VARARGIN)
% Choose default command line output for franck_guide
handles.output = hObject;
% Plot patch on uiaxes
%hold on
% Read experiment data from a CSV file
[~,~,data] = xlsread('excel_datafff.xlsx');
data(1,:) = []; % remove the header line
% randomly permute the rows of data without repeating the value:
data = data(randperm(size(data,1)),:);
numeric_data = cell2mat(data(:,[1 2 3 4 6]));
handles.v_thickness_1 = numeric_data(:,1); % numeric
handles.v_thickness_2 = numeric_data(:,2);
handles.h_thickness_1 = numeric_data(:,3);
handles.h_thickness_2 = numeric_data(:,4);
handles.amplitude = data(:,5); % cell array of char vectors
handles.v_or_h_array = numeric_data(:,5);
handles.f_df = data(:,7);
handles.exp_counter = 1;
handles.region1 = [];
% Create the Arduino serial object
handles.arduinoObj = serialport('COM3', 38400);
configureTerminator(handles.arduinoObj,'CR/LF');
%
for i=1:8
handles.message = readline(handles.arduinoObj);
disp(handles.message)
end
create_patch(handles);
function Next_button_Callback(hObject, eventdata, handles)
% hObject handle to Next_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)uiconfirm(handles.UIFigure,'Are You sure?','Confirm Close',...
handles = guidata(hObject);
f = msgbox('Operation Completed','NEXT');
handles.exp_counter = handles.exp_counter + 1;
if handles.exp_counter > numel(handles.v_thickness_1)
return
end
% delete the old patch and create a new one:
create_patch(handles);
  2 Kommentare
dpb
dpb am 10 Mai 2022
That would be up to you coding something in the callback function that does the notification -- what would be entirely up to you.
It's not possible to make much of the code you posted; it doesn't appear either of those two functions is complete; we don't see any corresponding "end" statements to indicate the end of the function.
What is in the standalone calculation routine is really of no bearing for this purpose, we would need to see the complete callback structure that starts the process and then how it goes on to more until it is finished...and then how do you know it is finished? Is there a counted loop somewhere, a list of files to process obtained from a call to dir() or what???
Simply incomplete information...
Franck paulin Ludovig pehn Mayo
Bearbeitet: Franck paulin Ludovig pehn Mayo am 10 Mai 2022
@dpb Below is all the code. In addition, On the figure , i would like all the experiment to be done between x=[-10 ;10] and y= [-10 ; 10] . The figure always centers the line on the screen. I was expecting to have some lines on the left , right depending on the coordinates.
function varargout = Hapticfinal(varargin)
% HAPTICFINAL MATLAB code for Hapticfinal.fig
% HAPTICFINAL, by itself, creates a new HAPTICFINAL or raises the existing
% singleton*.
%
% H = HAPTICFINAL returns the handle to a new HAPTICFINAL or the handle to
% the existing singleton*.
%
% HAPTICFINAL('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in HAPTICFINAL.M with the given input arguments.
%
% HAPTICFINAL('Property','Value',...) creates a new HAPTICFINAL or raises the
% existing singleton*. Starting from the left, property value pairs are
% handleslied to the GUI before Hapticfinal_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property handleslication
% stop. All inputs are passed to Hapticfinal_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 Hapticfinal
% Last Modified by GUIDE v2.5 17-Feb-2022 21:51:18
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Hapticfinal_OpeningFcn, ...
'gui_OutputFcn', @Hapticfinal_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 Hapticfinal is made visible.
function Hapticfinal_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 Hapticfinal (see VARARGIN)
% Choose default command line output for Hapticfinal
handles.output = hObject;
[~,~,data] = xlsread('excel_data.xlsx');
data(1,:) = []; % remove the header line
% randomly permute the rows of data:
data = data(randperm(size(data,1)),:);
numeric_data = cell2mat(data(:,[1 2 3 4 6]));
handles.v_thickness_1 = numeric_data(:,1); % numeric
handles.v_thickness_2 = numeric_data(:,2);
handles.h_thickness_1 = numeric_data(:,3);
handles.h_thickness_2 = numeric_data(:,4);
handles.amplitude = data(:,5); % cell array of char vectors
handles.v_or_h_array = numeric_data(:,5);
handles.f_df = data(:,7);
handles.exp_counter = 1;
handles.region1 = [];
% Create the Arduino serial object
handles.arduinoObj = serialport('COM3', 38400);
configureTerminator(handles.arduinoObj,'CR/LF');
%
for i=1:8
handles.message = readline(handles.arduinoObj);
disp(handles.message)
end
create_patch(handles);
% guidata(hObject, handles); % no longer necessary here
% UIWAIT makes Hapticfinal wait for user response (see UIRESUME)
% uiwait(handles.finger);
function create_patch(handles)
if ishandle(handles.region1)
delete(handles.region1);
end
v_or_h = handles.v_or_h_array(handles.exp_counter);
if v_or_h == 0 % Vertical line
v_thick1 = handles.v_thickness_1(handles.exp_counter);
v_thick2 = handles.v_thickness_2(handles.exp_counter);
handles.region1 = patch( ...
'Parent',handles.axes1, ...
'XData',[v_thick1 v_thick2 v_thick2 v_thick1], ...
'YData',[-10 -10 10 10], ...
'FaceColor','red');
set(handles.axes1,'XLim',[-5 0],'YLim',[-10 10]);
else % Horizontal line
h_thick1 = handles.h_thickness_1(handles.exp_counter);
h_thick2 = handles.h_thickness_2(handles.exp_counter);
handles.region1 = patch( ...
'Parent',handles.axes1, ...
'XData',[-10 10 10 -10], ...
'YData',[h_thick1 h_thick1 h_thick2 h_thick2], ...
'FaceColor','red');
set(handles.axes1,'YLim',[0 5],'XLim',[-10 10]);
end
set(handles.axes1,'XGrid','on','YGrid','on');
axis(handles.axes1,'equal');
% Update handles structure
guidata(handles.finger,handles);
% call the button motion fcn to update the new patch's color:
finger_WindowButtonMotionFcn(handles.finger);
% --- Outputs from this function are returned to the command line.
function varargout = Hapticfinal_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 mouse motion over figure - except title and menu.
function finger_WindowButtonMotionFcn(hObject,eventdata, handles)
% hObject handle to finger (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
pos = get(hObject, 'currentpoint'); % get mouse location on figure
global x;
global y;
x = pos(1);
y = pos(2); % assign locations to x and y
set(handles.xloc, 'string', ['x loc:' num2str(x)]); % update text for x loc
set(handles.yloc, 'string', ['y loc:' num2str(y)]); % update text for y loc
% Determine if mouse is within the region
p_x = get(handles.region1,'XData');
p_x = p_x([1 2]);
p_y = get(handles.region1,'YData');
p_y = p_y([1 3]);
ax_xl = get(handles.axes1,'XLim');
ax_yl = get(handles.axes1,'YLim');
ax_units = get(handles.axes1,'Units');
if ~strcmp(ax_units,'pixels')
set(handles.axes1,'Units','pixels')
end
ax_pos = get(handles.axes1,'Position'); % axes1 position in pixels
if ~strcmp(ax_units,'pixels')
set(handles.axes1,'Units',ax_units);
end
% convert the patch XData and YData from axes coordinates to figure coordinates in pixels
p_x = (p_x-ax_xl(1))/(ax_xl(2)-ax_xl(1))*ax_pos(3)+ax_pos(1);
p_y = (p_y-ax_yl(1))/(ax_yl(2)-ax_yl(1))*ax_pos(4)+ax_pos(2);
if x >= p_x(1) && x <= p_x(2) && y >= p_y(1) && y <= p_y(2)
set(handles.region1,'FaceColor','g');
writeline(handles.arduinoObj, handles.amplitude{handles.exp_counter})
else
set(handles.region1,'FaceColor','r');
writeline(handles.arduinoObj, '0&1!')
end
% % plot(handles.region1) % polygon
% axis equal
% hold on
% plot(handles.region1(in),'g+') % points inside
% %writeline(arduinoObj, "4&MOTOR_1_2&0!");
% plot(handles.region1(~in),'r+') % points outside
% %writeline(arduinoObj, "0&MOTOR_1_2_3_4&0!");
% drawnow;
% hold off
% guidata(hObject,handles);
% --- Executes on button press in Start_button.
%function Start_button_Callback(hObject, eventdata, handles)
% --- Executes on button press in Start_button.
function Start_button_Callback(hObject, eventdata, handles)
% hObject handle to Start_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%clear
%clc
handles.fileID = fopen('exp.txt','w');
handles.t = timer('ExecutionMode', 'fixedRate', ...
'Period', 0.5, ...
'TasksToExecute', Inf, ...
'TimerFcn', {@timerCallback, handles.finger});
start(handles.t);
set(handles.Start_button,'Enable','off'); % -> Disable the button
guidata(hObject,handles);% -----> do this to save the updated handles object
function timerCallback(~,~,f)
handles = guidata(f);
%fprintf(fileID,'(X, Y, time) = (%g, %g, %s)\n', get(0, 'PointerLocation'), datetime('now'));
fprintf(handles.fileID,'(X, Y, time) = (%g, %g, %s, %s, %s)\n', get(0, 'PointerLocation'), datetime('now'), ...
handles.amplitude{handles.exp_counter},handles.f_df{handles.exp_counter});
%fprintf('calling timer callback\n');
% --- Executes on button press in Stop_button.
function Stop_button_Callback(hObject, eventdata, handles)
% hObject handle to Stop_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
handles = guidata(hObject);
stop(handles.t) %whenever we want to stop.
fclose(handles.fileID);
set(handles.Start_button,'Enable','on'); % -> Enable the button
guidata(hObject,handles);
% --- Executes on button press in Yes_button.
function Yes_button_Callback(hObject, eventdata, handles)
% hObject handle to Yes_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
answer = questdlg('ARE YOU SURE?','Confirm close',...
'OK',@(src,event)mycallback(handles,src,event));
clear
clc
fileID= fopen('exp.txt2','a');
YES = "I FEEL IT";
fprintf (fileID, "%s\n",YES);
fclose(fileID);
% --- Executes on button press in NO_button.
function NO_button_Callback(hObject, eventdata, handles)
% hObject handle to NO_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
answer1= questdlg('ARE YOU SURE?','Confirm Close',...
'OK',@(src,event)mycallback(handles,src,event));
clear
clc
fileID= fopen('exp.txt2','a');
NO = "I DON'T FEEL IT";
fprintf (fileID, "%s\n",NO);
fclose(fileID);
% --- Executes on button press in Next_button.
function Next_button_Callback(hObject, eventdata, handles)
% hObject handle to Next_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)uiconfirm(handles.UIFigure,'Are You sure?','Confirm Close',...
handles = guidata(hObject);
f = msgbox('Operation Completed','NEXT');
handles.exp_counter = handles.exp_counter + 1;
if handles.exp_counter > numel(handles.v_thickness_1)
return
end
% delete the old patch and create a new one:
create_patch(handles);

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Voss
Voss am 10 Mai 2022
function Next_button_Callback(hObject, eventdata, handles)
% hObject handle to Next_button (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)uiconfirm(handles.UIFigure,'Are You sure?','Confirm Close',...
handles.exp_counter = handles.exp_counter + 1;
if handles.exp_counter > numel(handles.v_thickness_1)
msgbox('Experiment is Done!','DONE');
return
end
msgbox('Operation Completed','NEXT');
% delete the old patch and create a new one:
create_patch(handles);

Weitere Antworten (0)

Kategorien

Mehr zu Debugging and Analysis finden Sie in Help Center und File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by