私はこのコードを持っています。ここでは、軸1と2に表示されるプロットの種類をユーザーが決定するためのポップアップメニューがあります。活性化される。チェックマークが有効になっていると、ポップアップメニューの値が変更された場合、プロットが更新されます。これまでのところ、最初のプロットではうまくいきました。しかし、私はエラーコードが表示されます: "名前が重複している機能" myPlotFcn "を定義することはできません。すべてのプロットに対して新しい「myPlotFcn」を定義する必要がありますか、同じポップアップメニューから複数の(〜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