Problem displaying a counter on a GUİ
1 次查看(过去 30 天)
显示 更早的评论
Franck paulin Ludovig pehn Mayo
2022-5-17
评论: Franck paulin Ludovig pehn Mayo
2022-5-18
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);
0 个评论
采纳的回答
Voss
2022-5-17
编辑:Voss
2022-5-17
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!