이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Adjusting slider to scroll trough each image in 3D stack in GUI
조회 수: 9 (최근 30일)
이전 댓글 표시
Mario
2017년 8월 10일
Hi,
I am writing a small GUI (it is in the attachment) and I am having trouble adjusting the slider to work so that when I use the slider I will be able to scroll trough each image in a 3D stack.
Currently I am getting an error:
Warning: slider control can not have a Value outside of Min/Max range
and I am not sure how to solve it.
I am also trying to display the number of the current slice in this small GUI.
Any help would be appreciated.
Thanks!
채택된 답변
Stephen23
2017년 8월 10일
편집: Stephen23
2017년 12월 21일
Change the order in which you specify the parameters:
set(handles.hslider, 'Value', 1, 'Min', 1, 'Max', numel(filenames), ...
'SliderStep', [1,1]./(numel(filenames) - 1))
Otherwise you have a conflict because you change the Min value and this puts the default Value outside the min-max range (the input arguments are processed from left to right).
Addendum: to update a value continuously as a slider is moved see this answer:
댓글 수: 20
Mario
2017년 8월 10일
Hi Stephen,
When I change the order, I get an error:
Error using set
Value must be a 2 element vector
Error in untitled1>pushbutton1_Callback (line 127)
set(handles.hslider, 'Value', 1, 'Min', 1, 'Max', numel(filenames), ...
Mario
2017년 8월 10일
Yea, now that line of code works! Great!
But, now I got another error in hslider function:
Subscript indices must either be real positive integers or logicals.
Error in untitled1>hslider_Callback (line 83)
set(handles.image, 'CData', handles.imagedata{index});
Mario
2017년 8월 10일
I tried something similar before you posted your answer, but no luck.
I also tried your solution and I get an error:
Subscript indices must either be real positive integers or logicals.
Error in untitled1>hslider_Callback (line 82)
set(handles.image, 'CData', handles.imagedata{index});
Mario
2017년 8월 10일
That was the problem!
Now the slider works!
Any idea on how to display current slice number in the textbox below in GUI?
Stephen23
2017년 8월 10일
@Mario: add a textbox. Set its string using set.
PS: You should accept the answer that best resolves your original question. This is an easy way for you to thank the volunteers who helped you.
Mario
2017년 8월 10일
Hi Stephen,
Your help was greatly appreciated. Thanks!
Regarding the second part of the problem, I tried to write code for displaying current slice number in the textbox below in GUI, but I was not successful.
I placed my code under the textbox that I named textBox:
function textBox_CreateFcn(hObject, eventdata, handles)
sliderstate = get(handles.hslider,'value'); % Get the slider's info
enteredvalue = str2double(get(handles.textBox,'string')); % The new frame number
if enteredvalue >= sliderstate{1} && enteredvalue <= sliderstate{2} %Check if the new frame number actually exists
slidervalue=round(enteredvalue);
set(handles.hslider,'value',slidervalue) %If it does, move the slider there
else
set(handles.hslider,'string',sliderstate{3}) %User tried to set slider out of range, keep value
return
end
Any idea on how to finish it properly?
Stephen23
2017년 8월 10일
편집: Stephen23
2017년 8월 10일
@Mario: I do not understand what you want. Your code does the opposite of what you say you want to do. You state that you want to "display current slice number in the textbox below in GUI", but this line
enteredvalue = str2double(get(handles.textBox,'string'));
gets the text value and then you proceed to use it for setting the slider value. Do you want both the text and slider to update each others values? If the text is only for displaying the value (as you wrote) why do you get its value now?
Mario
2017년 8월 10일
I tried that option to see if I can make it work, but was unsuccessful. Now I focus only on displaying the value inside textBox.
How can I only store current slice number inside textBox while moving hslider?
Mario
2017년 8월 10일
I used your code, and replaced texbox handle with mine:
set(handles.textBox, 'string',str2double(get(hObject,'String')))
now in the GUI where the texbox should display a current slice number, it displays NaN while I move the slider trough the images.
Walter Roberson
2017년 8월 10일
if hObject is your slider then
set(handles.textBox, 'string', get(hObject,'Value') )
Stephen: it would not make sense to convert string to double to set the double as a string field: if you already had a string field then just copy it directly.
Mario
2017년 8월 10일
편집: Mario
2017년 8월 10일
Hi Walter,
the handle to my slider is defined as handles.hslider
When I type your code, the text box displays only 1 while I move the slider trough the image stack.
I tried even with:
set(handles.textBox, 'string', get(handles.hslider,'Value') )
but the result is the same.
Stephen23
2017년 8월 10일
편집: Stephen23
2017년 8월 10일
@Mario: The behavior of the slider uicontrol object is to change the value after releasing with the mouse. The is explained clearly in the documentation: " The location of the thumb indicates a numeric value, assigned to the Value property when you release the mouse button."
If you want the value to be updated while you are sliding the bar then you will need to add a listener. Exactly how depends on the MATLAB version that you have. In any case you will find many examples on this forum, so use the search field in the top corner and search for "slider listener".
Mario
2017년 8월 11일
@Stephen: thanks you for your valuable suggestions and links. I am trying to write a code using listeners based from those links that you provided me, but no luck.
Why is it so hard to write this code (as I saw from many other discussions) using GUIDE?
I tried your "4 line of code" solution to test it that you mentioned here and I am still confused on how to proceed with this using GUIDE.
I even tried @Jan Simon solution, but did not solve the problem.
추가 답변 (1개)
Arjun Chawla
2017년 12월 20일
Hi Mario, can you please upload your final gui code, that would be greatly appreciated. Thanks!
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)