Multiple Push buttons Use the same process, how can I condense?
Afficher commentaires plus anciens
I am analyzing an image within a GUI. I can tilt the image in the x or y directions as this is sometimes necessary for a clearer picture. 4 different push buttons control the direction of the tilt, 1 for the +x direction, 1 for -x, 1 for +y, and 1 for -y. Each of these buttons has a segment of similar code. Is there a way to condense this, so I don't have the same lines of code repeated 4 times? I tried to make a separate function and call on that, but I kept having an error that I had referenced a non existent field. Here is some relevant code:
% --- Executes on button press in plusx.
function plusx_Callback(hObject, eventdata, handles)
% hObject handle to plusx (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Xtilt = handles.analyze_button_Xtilt;
planeX = handles.analyze_button_planeX;
Img1 = handles.analyze_button_Img1;
S_temp = str2double(get(handles.sensitivity,'String'));
if isnan(S_temp)
uiwait(msgbox('Please insert a non negative number in the Sensitivity
box','Error'));
S_out = 0;
elseif S_temp < 0
set(handles.sensitivity,'String','0')
uiwait(msgbox('Please insert a non negative number in the Sensitivity box','Error'));
S_out = 0;
elseif S_temp >= 0
S_out=S_temp;
end
S = S_out;
Img1 = Img1 + planeX * S;
Xtilt = Xtilt + S;
handles.analyze_button_Xtilt = Xtilt; handles.analyze_button_Img1 = Img1;
UpdatePlots(hObject, eventdata, handles);
The parts that are the same for all 4 buttons are the if statements, starting with "S_temp = str2double(get(handles.sensitivity,'String'));" and ending with "S = S_out;". Any help is appreciated.
Réponses (0)
Catégories
En savoir plus sur MATLAB Support Package for Parrot Drones dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!