我正在制作一个GUI,我正在使用它的指南。在写我的问题之前,我必须解释一些细节,它们是:数据的-Kind :文本文件,来自人体两条腿的16块肌肉肌电的数据,所以我必须绘制16张图表。我的图形用户界面的-Objective是显示4在每个“页面”,所以我需要下一个按钮和后退按钮,能够看到所有的16个graphs.In其他词,我的GUI需要4个“页面”。-My指南由1次底部浏览我的数据,1次底部切换(更新)4个图形的形状显示在ABS中,图与信封,和一个组合的ABS和包络图,一个菜单来切换显示的图形的形状,和两个额外的底部,一个是下一个按钮,另一个是后退按钮。
总之,我只是停留在如何创建下一个按钮和后退按钮。我的代码的其他角色已经开发出来了。
提前谢谢。
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
->>>>>>>It是我的更新功能。
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);
->>>>>>>>>Popmenu函数
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,而且我有很多疑问。
谢谢
发布于 2014-06-25 10:16:55
让我纠正你的代码,告诉你你犯的小错误(我不是很有经验,但我认为这能帮你)。我没有试图理解textscan(...)
调用,因为我没有您的一个txt文件。
function Search_Patient_Callback(hObject, eventdata, handles)
% global cell_data (I avoid global variables)
[file, path]=uigetfile('*.txt', 'Select file');
% arq = [path,file]; (it is the same as below, no ?)
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(full_pathname,'r');
textscan(fileID, '%[^\n\r]', startRow-1, 'ReturnOnError', false);
dataArray = textscan(fileID, formatSpec, endRow-startRow+1, 'Delimiter', delimiter, 'ReturnOnError', false);
time_foot1 = dataArray{:, 1};
% Now store the relevant data in the handles structure :
handles.timefoot=timefoot1;
handles.cell_data=cell_data;
guidata(hObject,handles); % This line saves the current handles (so it saves the changes above)
% handles = guidata(hObject); % This line replaces current handles with the one stored. Use it only in the beginning of a function that doesn't take handles as an input, or after a call to a function that affects handles.
然后
function Updating_Callback(hObject, eventdata, handles)
y_data=0.001;
t=(handles.cell_data{1,1})/1000; % else you can say 'cell_data=handles.cell_data;' and use 'cell_data' as you did
%time_foot1= getappdata(0,'time_foot'); (let is use the handles structure instead of getappdata)
time_foot1=handles.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(handles.cell_data); % EMG RMS and EMG Envelope
popup_sel_index = get(handles.popupmenu, 'Value');
switch popup_sel_index
[skipping a few lines]
end
% a=get(handles.next_pushbutton,'Value') (what for ??)
% handles = guidata(hObject) (you do not want to erase the handles structure do you ?)
guidata(hObject,handles); % OK but not neccesary because nothing changed in the handles structure in the function)
现在,,您想要做的事情,是修改您的更新函数,以便它考虑到您推送上一个/返回的次数。我认为。因此,我将在GUI handles.index=1
中创建一个简单的变量OpeningFcn
(别忘了用guidata
保存它),每次按下其中一个按钮,就会修改它的值(+1或-1)。然后在更新函数中,newIndex=mod(handles.index,4);
和newIndex告诉您必须显示哪个“平面”。
另一种解决方案是使用另一个带有字符串{'1','2','3','4'}
的弹出菜单,并在您已经使用它时使用它。
https://stackoverflow.com/questions/24370554
复制相似问题