How can I link a scroll-bar GUI with the mathematical code I have written?
이전 댓글 표시
I am trying to write a program using GUIDE that has several scroll-bars. The program is going to plot a interference pattern of two point-sources of light varying certain variables using the scroll-bars. I have the math part of the code working and have some sort of the GUI as well. However, I cannot seem to get the two working together. The scroll-bars wont seem to vary the math part of the code.
If anybody could give me any advice I would greatly appreciate it.
댓글 수: 1
Nicholas
2012년 11월 19일
I'm not exactly sure what your question here is, however I can tell you that by default the sliders update only when the mouse button is released. A few weeks ago, though, I found some code on here that added "real time sliders". I can't find the exact link right now, but I have the code that I used.
function figure1_WindowButtonMotionFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
obj = get(YOURMAINFIGUREWINDOW, 'CurrentObject');
if ~isempty(obj)
if obj == YOURSLIDERHANDLE
set(YOURSLIDERHANDLE, 'Value', round(num2str(get(YOURSLIDERHANDLE, 'Value')) / 5)* 5 ) ); %%I was rounding the value here
set(SOMEDISPLAYHANDLE, 'String', num2str(get(YOURSLIDERHANDLE, 'Value'))); %%This line sets the handle value to an output
end
end
What this does is find which object your mouse is hovering over, and if it's a slider, it replaces a display value with that number. Instead of replacing a display value, you could perform a math function.
This should work, if not, I apologize as I'm not really a qualified expert.
채택된 답변
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Lighting, Transparency, and Shading에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!