Borrar filtros
Borrar filtros

Problem displaying a counter on a GUİ

1 visualización (últimos 30 días)
Franck paulin Ludovig pehn Mayo
Franck paulin Ludovig pehn Mayo el 17 de Mayo de 2022
Hello everyone
İ am trying to display a counter on a GUİ.
Each time i click on a Next button , how is the counter going. The counter info is coming from excel.
İ have already used a static text in the gui and i renamed it exp_counter . İ would like just to display what is happening in the background.
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_data_final.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);
handles.exp_counter = handles.exp_counter + 1;
if handles.exp_counter > numel(handles.v_thickness_1)
% set(handles.exp_counter);
msgbox('Experiment is Done!','DONE');
return
end
f = msgbox('Operation Completed','NEXT');
% delete the old patch and create a new one:
create_patch(handles);

Respuesta aceptada

Voss
Voss el 17 de Mayo de 2022
Editada: Voss el 17 de Mayo de 2022
If your static text is called handles.exp_counter, then that's going to be a problem because the name handles.exp_counter already refers to the counter variable (initialized to 1 in the OpeningFcn and incremented by 1 in Next_button_Callback).
Instead, call your static text something else, e.g., handles.text_exp_counter, and then set its String in the OpeningFcn and in Next_button_Callback (i.e., whenever the counter handles.exp_counter changes):
function franck_guide_OpeningFcn(hObject, eventdata, handles, varargin)
% ...
% ...
handles.exp_counter = 1;
set(handles.text_exp_counter,'String',num2str(handles.exp_counter));
% ...
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);
new_counter = handles.exp_counter + 1;
if new_counter > numel(handles.v_thickness_1)
msgbox('Experiment is Done!','DONE');
return
end
f = msgbox('Operation Completed','NEXT');
set(handles.text_exp_counter,'String',num2str(new_counter));
handles.exp_counter = new_counter;
% delete the old patch and create a new one:
create_patch(handles); % this calls guidata(), which stores the new handles.exp_counter value
(doing num2str is not strictly necessary)
  5 comentarios
Voss
Voss el 17 de Mayo de 2022
Excellent! You're welcome!
Franck paulin Ludovig pehn Mayo
Franck paulin Ludovig pehn Mayo el 18 de Mayo de 2022
@_ would you mind having a look on he following ? I am trying to implement a Pause button

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by