現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Adjusting slider to scroll trough each image in 3D stack in GUI
11 ビュー (過去 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});
Stephen23
2017 年 8 月 10 日
編集済み: Stephen23
2017 年 8 月 10 日
if numel(handles.imagedata)>=index
set(handles.image, 'CData', handles.imagedata{index});
end
Most likely this happens when the objects are being initialized. You could check that by adding an else and displaying some the value in the command window.
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!
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)