Hello all! Well I'm attempting to change the position property of a GUI. I need to display different parts of a GUI at different times. So I have an example here showing two text boxes that show upper data and lower data, I need to resize the GUI to fit the lower data then fit the upper data. I know I can get the lower half easy, but the upper half is being a pain. Here is the example code:
% Make figure 1
f1 = figure('Name','Window 1');
%Add some text boxes
u1 = uicontrol(f1, ...
'Style','text', ...
'String','Upper Data', ...
'Callback','feval(plotf)', ...
'position', [250 380 100 15]);
u1 = uicontrol(f1, ...
'Style','text', ...
'String','Lower Data', ...
'Callback','feval(plotf)', ...
'position', [250 20 100 15]);
%grab current position data
get(gcf,'position')
%so you see both the upper and lower regions
pause(2)
%set new data
set(gcf,'position', [677 610 560 210])
What I need is to find a way to get essentially a position of:
set(gcf,'position', [677 610 560 210:420])
But that code is not the correct way to accomplish this. I need is a way to display the upper regions just like I display the lower regions.
Please help!
Thanks

5 commentaires

Sara
Sara le 11 Juil 2014
I don't understand why you have an interval instead of one value here: 210:420
set(gcf,'position', [677 610 560 210:420])
Chris E.
Chris E. le 11 Juil 2014
If the code worked that way it would of solved my issue, but I know the code does not work. One value is not what I need, I need an area of interest, the area of 210:420. I need to exclude the area of 0:210. That way I only have the "upper" area shown and not the lower area shown.
If, for example I put one value, 420, then I get the full GUI from 0:420 to show up, I do not what to show the area of 0:210.
I hope that answers your question!
Sara
Sara le 11 Juil 2014
Modifié(e) : Sara le 11 Juil 2014
The #4 element of position is the height of the panel, so a range does not make sense. You need to change the position of the bottom border, i.e. element #2. Try this
pos = get(gcf,'position');
set(gcf,'position', [pos(1:3) pos(4)/2])
Is that what you want???
Joseph Cheng
Joseph Cheng le 11 Juil 2014
yes Sara is absolutely correct. the position parameter properties is [xposition yposition width height].
Hello Sara and Joseph,
Well I know that position parameter properties goes like this: [xposition yposition width height], but I was hoping for was a way to look at part of a gui that is located at the top of the gui. Well the code you gave:
pos = get(gcf,'position');
set(gcf,'position', [pos(1:3) pos(4)/2])
is what I already have and know.
Essentially I need:
% Make figure 1
f1 = figure('Name','Window 1');
u1 = uicontrol(f1, ...
'Style','text', ...
'String','Upper Data', ...
'Callback','feval(plotf)', ...
'position', [250 180 100 15]);
%NOTE I physically changed the position of the txt to match what I want, in the real situation I can not change the position of the txt
set(gcf,'position', [677 610 560 210])
%Also the "upper data" is in the area of [677 610 560 420] not [677 610 560 210] (changed it so you know what it needs to look like), I have to find a way to display data that is in the upper portion of the GUI but not the lower portion of a GUI.
But I can not move the positions of the txt boxes, I need to move the position of the GUI, The more I'm thinking about it the more i think it is not possible in this setup for position in GUI's.
My task was to change the GUI without changing the positions of the information inside it.
I hope that maybe clarifies what I need.
Thank you though! I very much appreciate any help anyone is willing to offer!!!

Connectez-vous pour commenter.

 Réponse acceptée

Joseph Cheng
Joseph Cheng le 11 Juil 2014

0 votes

as the position parameter starts with what i remember as the lower left corner you cannot just resize the figure to show the top portion. since if you resize it the bottom corner is locked to the bottom corner of the window. What you can do is shift the everything else!
% Make figure 1
f1 = figure('Name','Window 1');
%grab/set current position data
fposition = get(gcf,'position')
yoffset = [0 fposition(4)/2 0 0];
u1pos = [250 20 100 15];
u2pos = [250 380 100 15];
%Add some text boxes
u2 = uicontrol(f1, ...
'Style','text', ...
'String','Upper Data', ...
'Callback','feval(plotf)', ...
'position', u2pos);
u1 = uicontrol(f1, ...
'Style','text', ...
'String','Lower Data', ...
'Callback','feval(plotf)', ...
'position', u1pos);
%so you see both the upper and lower regions
pause(2)
%set new data
% set(gcf,'position', [677 610 560 210])
set(gcf,'position',[fposition(1:3) fposition(4)/2])
% What I need is to find a way to get essentially a position of:
pause(2)
set(u1,'position',u1pos-yoffset);
set(u2,'position',u2pos-yoffset);

4 commentaires

Joseph Cheng
Joseph Cheng le 11 Juil 2014
Modifié(e) : Joseph Cheng le 11 Juil 2014
so you want to keep the position of the window to match the upper half? think about it a bit more. if you're able to resize the window by x amount and move things by y amount and everything is in relative to the bottom corner (window and monitor).
%coded stuff above
pause(2)
set(u1,'position',u1pos-yoffset);
set(u2,'position',u2pos-yoffset);
set(gcf,'position',get(gcf,'position')+yoffset);
wit this the "top" half should stay in place.
Chris E.
Chris E. le 11 Juil 2014
I think I may have to do that in the long run, but it will be annoying. In the example I gave it had only2 text boxes. in the real life GUI I will be modifying, it will have hundreads of bits of stuff that will need to be shifted. BUT shifting them the way you do may be a better way then using the eyeball and drag method or put numbers in till it looks good method (yikes!).
Well thank you for your response!
Chris
well... without digging up for more info you can set the position for multiple items... so group them like i did here i know i grouped both the top and bottom but see what i was trying to do. group all your top stuff with under a variable TOP or here i did U. so setting the handles inside U, to the cell representation of the position it'll offset everything inside U by that amount. probably a cleaner way to show the new position matrix. if you're not familiar with mat2cell look at the documentation and i'm using the rowDist parameter where i'm saying break up the matrix into one row per cell.
u2 = uicontrol(f1, ...
'Style','text', ...
'String','Upper Data', ...
'Callback','feval(plotf)', ...
'position', u2pos);
u1 = uicontrol(f1, ...
'Style','text', ...
'String','Lower Data', ...
'Callback','feval(plotf)', ...
'position', u1pos);
pause(3)
U = [u1 u2];
Upos = [u1pos;u2pos];
%shift all by xoffset
xoffset = 20;
set(U,{'position'},mat2cell(Upos+[xoffset*ones(length(U),1) zeros(length(U),3)],ones(length(U),1)))
Joseph Cheng
Joseph Cheng le 11 Juil 2014
so i'd recommend create a function that takes inputs of handles,x, y and top/bottom/left/right so all you need to do then do what i did above for all the items. so you only have to write this up once.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by