我有这个代码,其中有一个弹出菜单供用户决定要在轴1和2中显示的绘图类型。只有当复选标记为活性。如果复选标记已激活,则如果popupmenu值发生更改,则绘图应该更新。到目前为止,它对第一个情节工作良好。但是我得到一个错误代码:“具有重复名称的函数”myPlotFcn“无法定义。”我是否必须为每个情节定义一个新的“myPlotFcn”,还是有更平滑的方法来控制同一个popupmenu中的多个(〜50)情节?这里是我的代码:通过GUI中的相同弹出菜单控制的多个绘图
% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
myPlotFcn(handles);
function popupmenu1_CreateFcn(hObject, eventdata, handles)
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in checkbox1.
function checkbox1_Callback(hObject, eventdata, handles)
myPlotFcn(handles);
function myPlotFcn(handles)
isChecked = get(handles.checkbox1,'value');
if(isChecked)
contents = get(handles.popupmenu1,'String');
popupmenu1value = contents{get(handles.popupmenu1,'Value')};
switch popupmenu1value
case 'Raw CD [mdeg]'
rawdata=handles.rawdata;
x1=rawdata{1,2}(:,1);
cd1raw=(rawdata{1,2}(:,2)-rawdata{1,1}(:,2));%sample-buffer
cd1raw=cd1raw-cd1raw(1,1); %normalize to y=0 at 250 nm
CD=cd1raw;
ht1=rawdata{1,2}(:,3);
%hold(handles.axes1, 'on')
handles.plotCD1 = plot(x1,CD,'LineWidth',2,'Color', [0 0 0],'parent',handles.axes1);
%hold(handles.axes2, 'on')
handles.plotHT1 = plot(x1,ht1,'LineWidth',2,'Color', [0 0 0],'parent',handles.axes2);
guidata(handles.plotCD1,handles);
guidata(handles.plotHT1,handles);
case 'Molar ellipticity [deg cm^2 dmol^-1]'
mg_ml_Conc=handles.mg_ml_Conc;
Length=handles.Length;
Mass=handles.Mass;
rawdata=handles.rawdata;
x1=rawdata{1,2}(:,1);
cd1raw=(rawdata{1,2}(:,2)-rawdata{1,1}(:,2));%sample-buffer
cd1raw=cd1raw-cd1raw(1,1); %normalize to y=0 at 250 nm
CD=((cd1raw*Mass(1,1))/(10*Length(1,1)*mg_ml_Conc(1,1)));
%molar ellipticity=cdraw*mw/(10*cell-length(cm)*concentration(mg/ml))
ht1=rawdata{1,2}(:,3);
%hold(handles.axes1, 'on')
handles.plotCD1 = plot(x1,CD,'LineWidth',2,'Color', [0 0 0],'parent',handles.axes1);
%hold(handles.axes2, 'on')
handles.plotHT1 = plot(x1,ht1,'LineWidth',2,'Color', [0 0 0],'parent',handles.axes2);
guidata(handles.plotCD1,handles);
guidata(handles.plotHT1,handles);
case 'Mean residue ellipticity [deg cm^2 dmol^-1 residue^-1]'
Length=handles.Length;
mg_ml_Conc=handles.mg_ml_Conc;
Mass=handles.Mass;
Peptide=handles.Peptide;
rawdata=handles.rawdata;
x1=rawdata{1,2}(:,1);
cd1raw=(rawdata{1,2}(:,2)-rawdata{1,1}(:,2));%sample-buffer
cd1raw=cd1raw-cd1raw(1,1); %normalize to y=0 at 250 nm
CD=(cd1raw/1000*100)/(Length(1,1)*mg_ml_Conc(1,1)/Mass(1,1)*Peptide(1,1));
%Normalized data:(abscorrected/1000*100)/(pathlength*concentration(mg/ml)/Mw*no. of peptidebonds)
ht1=rawdata{1,2}(:,3);
%hold(handles.axes1, 'on')
handles.plotCD1 = plot(x1,CD,'LineWidth',2,'Color', [0 0 0],'parent',handles.axes1);
%hold(handles.axes2, 'on')
handles.plotHT1 = plot(x1,ht1,'LineWidth',2,'Color', [0 0 0],'parent',handles.axes2);
guidata(handles.plotCD1,handles);
guidata(handles.plotHT1,handles);
end
else
if ~isempty(handles.plotCD1)
delete(handles.plotCD1)
~isempty(handles.plotHT1)
delete(handles.plotHT1)
set(handles.text2, 'BackgroundColor', [0.94 0.94 0.94]);
end
end
% --- Executes on button press in checkbox3.
function checkbox3_Callback(hObject, eventdata, handles)
myPlotFcn(handles);
function myPlotFcn(handles)
isChecked = get(handles.checkbox3,'value');
if(isChecked)
contents = get(handles.popupmenu1,'String');
popupmenu1value = contents{get(handles.popupmenu1,'Value')};
switch popupmenu1value
case 'Raw CD [mdeg]'
rawdata=handles.rawdata;
x1=rawdata{1,2}(:,1);
cd1raw=(rawdata{1,2}(:,2)-rawdata{1,1}(:,2));%sample-buffer
cd1raw=cd1raw-cd1raw(1,1); %normalize to y=0 at 250 nm
CD=cd1raw;
ht1=rawdata{1,2}(:,3);
%hold(handles.axes1, 'on')
handles.plotCD1Adj = plot(x1,CD,'LineWidth',2,'Color', [0 0 0],'parent',handles.axes1);
%hold(handles.axes2, 'on')
handles.plotHT1Adj = plot(x1,ht1,'LineWidth',2,'Color', [0 0 0],'parent',handles.axes2);
guidata(handles.plotCD1Adj,handles);
guidata(handles.plotHT1Adj,handles);
case 'Molar ellipticity [deg cm^2 dmol^-1]'
... and so on similar to the above checkbox, but with different x,y values
我猜的代码是一个有点笨拙等了更干净的代码将包含50个复选框任何建议高度赞赏。谢谢。
Matlab是正确的...为什么你使用不同的功能相同的名称?如何调试它,例如...?你为什么不“结束”你的功能?这真是令人困惑。 – Adiel