【发布时间】:2014-06-25 18:16:55
【问题描述】:
我正在制作一个 GUI,我正在使用 GUIDE。在写我的问题之前,我必须解释一些细节,所以它们是: - 数据类型:文本文件,来自 2 个人腿的 16 块肌肉的 EMG 数据,所以我必须绘制 16 个图表。 - 我的 GUI 的目标是在每个“页面”中显示 4 个,所以我需要下一个和后退按钮才能看到所有 16 个图形。换句话说,我的 Gui 需要 4 个“页面”。 - 我的指南由 1 次按下底部浏览我的数据、1 次按下底部以切换(更新)4 个图形的形状在 ABS 中显示为波形、带包络的图形以及 ABS 和包络图的组合、1 个用于切换的弹出菜单显示图形的形状,还有两个额外的按钮,一个是下一个按钮,另一个是返回按钮。
总而言之,我只是纠结于如何创建下一个和后退按钮。我的代码的其他角色已经开发完毕。
提前致谢。
Ps:感谢建议我改进问题的人。
是的,我想重绘我的图表(我的英语不太好,所以我无法更好地解释)
->>>>>> 这是我的浏览器功能
function Search_Patient_Callback(hObject, eventdata, handles)
% hObject handle to Search_Patient (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of Search_Patient
global cell_data
[file, path]=uigetfile('*.txt', 'Select file');
arq = [path,file];
full_pathname=strcat(path,file);
text=fileread(full_pathname);
cell_data= textscan(text, repmat('%f',1,41),'headerlines',11);
delimiter = '\t';
startRow = 3;
endRow = 8;
formatSpec = '%*s%*s%*s%f%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%*s%[^\n\r]';
fileID = fopen(arq,'r');
textscan(fileID, '%[^\n\r]', startRow-1, 'ReturnOnError', false);
dataArray = textscan(fileID, formatSpec, endRow-startRow+1, 'Delimiter', delimiter, 'ReturnOnError', false);
time_foot1 = dataArray{:, 1};
%h = handles.Search_Patient;
%setappdata(0,'My_main_Data',cell_data)
setappdata(0,'time_foot',time_foot1)
handles = guidata(hObject); %Updating variables
guidata(hObject,handles); %Updating variables
->>>>>>>这是我的更新功能。
function Updating_Callback(hObject, eventdata, handles)
% hObject handle to Updating (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global cell_data
y_data=0.001;
t=(cell_data{1,1})/1000;
time_foot1= getappdata(0,'time_foot');
text_rfoot=0.0009;
text_lfoot=0.0007;
[emg1_1 emg2_1 emg3_1 emg4_1 emg1e_1 emg2e_1 emg3e_1 emg4e_1]=emg_signal(cell_data); % EMG RMS and EMG Envelope
popup_sel_index = get(handles.popupmenu, 'Value');
switch popup_sel_index
case 1
axes (handles.axes1);
plot (t,emg1_1,'r-');
title('EMG Left Vastus medialis : ' )
xlabel('Time(s)')
ylabel('Voltage (uV)')
axes (handles.axes2);
plot (t,emg2_1,'r-');
axes (handles.axes3);
plot (t,emg3_1,'r-');
axes (handles.axes4);
plot (t,emg4_1,'r-');
axis ([t(1) (t(1)+(length (t')/1000)) 0 y_data])
%Right-Foot Strike1
text(time_foot1(4),text_rfoot, ' Right-Strike 1', 'Color', 'k')
line('XData',[time_foot1(4) time_foot1(4)], 'YData', [0 y_data], 'LineStyle', '-','LineWidth', 1, 'Color','k');
%Right Foot Off
text(time_foot1(6),text_rfoot, ' Right-Off', 'Color', 'k')
line('XData',[time_foot1(6) time_foot1(6)], 'YData', [0 y_data], 'LineStyle', '-','LineWidth', 1, 'Color','k');
%Right-Foot Strike2
text(time_foot1(5),text_rfoot, ' Right-Strike 2', 'Color', 'k')
line('XData',[time_foot1(5) time_foot1(5)], 'YData', [0 y_data], 'LineStyle', '-','LineWidth', 1, 'Color','k');
%Left-Foot Strike
text(time_foot1(1),text_lfoot, ' Left-Strike', 'Color', 'b')
line('XData',[time_foot1(1) time_foot1(1)], 'YData', [0 y_data], 'LineStyle', '-','LineWidth', 1, 'Color','b');
%Left Foot Off
text(time_foot1(3),text_lfoot, ' Left-Off', 'Color', 'b')
line('XData',[time_foot1(3) time_foot1(3)], 'YData', [0 y_data], 'LineStyle', '-','LineWidth', 1, 'Color','b');
title('EMG Left Vastus medialis : ' )
xlabel('Time(s)')
ylabel('Voltage (uV)')
case 2
axes (handles.axes1);
plot (t,emg1e_1,'b-','linewidth', 2);
title('EMG Left Vastus medialis : ' )
xlabel('Time(s)')
ylabel('Voltage (uV)')
axes (handles.axes2);
plot (t,emg2e_1,'b-','linewidth', 2);
axes (handles.axes3);
plot (t,emg3e_1,'b-','linewidth', 2);
axes (handles.axes4);
plot (t,emg4e_1,'b-','linewidth', 2);
case 3
axes (handles.axes1);
plot (t,emg1_1,'r-');
hold on
plot (t,emg1e_1,'b-','linewidth', 2);
hold off
axes (handles.axes2);
plot (t,emg2_1,'r-');
hold on
plot (t,emg2e_1,'b-','linewidth', 2);
hold off
axes (handles.axes3);
plot (t,emg3_1,'r-');
hold on
plot (t,emg3e_1,'b-','linewidth', 2);
hold off
axes (handles.axes4);
plot (t,emg4_1,'r-');
hold on
plot (t,emg4e_1,'b-','linewidth', 2);
hold off
end
a=get(handles.next_pushbutton,'Value')
handles = guidata(hObject)
guidata(hObject,handles);
->>>>>>>>>弹出菜单功能
function popupmenu_CreateFcn(hObject, eventdata, handles)
% hObject handle to popupmenu (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: popupmenu controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
set(hObject, 'String', {'EMG_abs','EMG_Envelope','EMG_abs + EMG_Envelope'})
set(hObject, 'String', {'EMG_abs','EMG_Envelope','EMG_abs + EMG_Envelope'})
我所有的代码都在这里,我不知道我所做的是否是在 Matlab 中编程的最佳方式,因为这是我正在制作的第一个 GUI,我有很多疑问。
谢谢
【问题讨论】:
-
有人否决了您的问题,可能是因为它没有提供足够的细节。我想到了几个问题:你使用 GUIDE 吗?你需要你的按钮来做什么?只更改 4 个图表?您尝试了什么(我不知道您为什么尝试 while 循环)?您的数据是如何存储的?无论如何,我会创建一个变量(我们称之为handles.index),并且每个按下的后退/下一个按钮都会修改它的值(1、2、3 或4)。然后将运行一个函数来实现handles.index 值之后的图形。
-
我仍然认为您的 GUI 上不需要有 4 个“页面”。按下这些上一个/下一个按钮之一后,简单地重新绘制图形会更简单。如果您不明白我的意思,您必须将您的图表代码添加到您的问题中,以便我们看到您如何显示它们。
-
是的,我真的很想重绘。谢谢。附言。我的英语不太好,所以我无法更好地表达我的疑问。
标签: matlab matlab-guide