How to send data in edit box to different fig. window.

6 ビュー (過去 30 日間)
Samuel
Samuel 2011 年 2 月 20 日
Hi,
I like to send a value of editbox in A fig. to B. fig. With the value, I like to set max of a slider.
I successed this in the same figure window, but failed in differents figure windows.
if anyone know, please let me know.
Thansk.
  1 件のコメント
Samuel
Samuel 2011 年 2 月 20 日
here is my code..
RBslider = findall(0,'type','slider','tag','RBslider');
set(RBslider,'Max',R*2);
set(RBRslider,'Value',R);

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2011 年 2 月 20 日
Edit: Missing brackets corrected, thanks to Paulo's keen eye. Also, missed a 'Parent' I meant to include.
Matlab doesn't care which figure the control is in: it just needs the handle of the control.
fig2 = figure(2);
slideh = uicontrol('Style','slider','Parent',fig2);
fig3 = figure(3);
eb = uicontrol('Style','edit', 'Parent', fig3, 'Callback', ...
@(src,event) set(slideh, 'Value',str2double(get(src,'String'))));
Or even
fig2 = figure(2);
slideh = uicontrol('Style','slider','Parent',fig2, 'Tag', 'Here');
fig3 = figure(3);
eb = uicontrol('Style','edit', 'Callback', ...
@(src,event) set(findobj(0, 'Tag', 'Here'), ...
'Value',str2double(get(src,'String'))));
The problem with your code is that there is no type 'slider'. Sliders are 'type' 'uicontrol', with 'style' 'slider'
  1 件のコメント
Paulo Silva
Paulo Silva 2011 年 2 月 20 日
Interesting code Walter but you need to add another ) at the end of both examples :)
(Ignore this if you already corrected it)

サインインしてコメントする。

その他の回答 (3 件)

Samuel
Samuel 2011 年 2 月 20 日
Thank you for your answer.
Is fig2 in my new fig. window? Is fig3 in my current window?
What do 2, and 3 in figure() represent? are they my figure windows name??
Where put these code? I made fig.window by matlab GUIDE. there are many function blocks.
  2 件のコメント
Paulo Silva
Paulo Silva 2011 年 2 月 20 日
doc figure
You will find this:
figure(h) does one of two things, depending on whether or not a figure with handle h exists. If h is the handle to an existing figure, figure(h) makes the figure identified by h the current figure, makes it visible, and raises it above all other figures on the screen. The current figure is the target for graphics output. If h is not the handle to an existing figure, but is an integer, figure(h) creates a figure and assigns it the handle h. figure(h) where h is not the handle to a figure, and is not an integer, is an error.
h = figure(...) returns the handle to the figure object.
Walter Roberson
Walter Roberson 2011 年 2 月 20 日
Questions about "new" figure window and "current" window cannot be answered without more context.
I used explicit figure numbers to show that the code was not restricted to dealing with the "current figure" and "another figure". On only restriction in the first example is that the slider handle needs to be created before it can be referred to in the callback for the edit box. The callback could, however, be set() after the slider had been created.

サインインしてコメントする。


Samuel
Samuel 2011 年 2 月 20 日
It's still too difficult for me. I just start to learn matlab. Do you mind if I ask you make a sime examples???
If I solve this problem, I could finish my project.
Thanks.
  3 件のコメント
Samuel
Samuel 2011 年 2 月 20 日
Wow!!!! it works. Really appreciate!!
But, I fill this is not recommanded way. isn't it?
Walter Roberson
Walter Roberson 2011 年 2 月 21 日
Finding by Tag is generally considered acceptable for unique items.
Personally I consider it to be on par with global variables... though I don't dislike global variables as much as most people do.

サインインしてコメントする。


Samuel
Samuel 2011 年 2 月 20 日
Please take a look my code one more time. I can plot on my new figure. But it still doesn't send data. My new fig. is bandGraphGUI and it remains in open when I click pushbutton on the other fig.
% Set Rslider Max and Value, fig2 = bandGraphGUI; RBslider = uicontrol('Style','slider','Parent',fig2,'Tag','RBslider'); set(RBslider,'Max',R*2); set(RBslider,'Value',R); % Display Rslidertext, Rslidertext = uicontrol('style','text','Parent',fig2,'tag','RBslidertext'); str1=sprintf('R : %5.1f',R); set(Rslidertext,'string',str1);
  1 件のコメント
Walter Roberson
Walter Roberson 2011 年 2 月 20 日
You will want to use an explicit Position for your uicontrol() calls.
There is nothing obviously wrong with the code you show, but you do not show the edit box or the callback of the edit box that should cause the new slider value to be set.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCreating, Deleting, and Querying Graphics Objects についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by