Clear Filters
Clear Filters

2 axes in GUI, permanently set the max and min values of the X and Y Coordinates.

1 view (last 30 days)
I have 2 axes in a GUI, axes1 and axes2.
I have the sizes of the axes set. When I hit "Run Figure," the size of axes1 changes (becomes a 1X1 square).
I want to keep the size of axes1 the same, but change the maximum and minimum values for the y and x coordinate axes while keeping the scale of the axes1 the same. I start with this,
but when I hit "run figure" I get this, where the size of the axes has changed.:
Also, now I want to set the max and min for the x and y coordinates, but
axes(handles.axes1)
axis([0 300 0 100]);
does something that causes axes to disappear entirely. Please help!!
Thank you!
Also, if I want set a patch to axes2, how do I do that?

Answers (2)

Ben11
Ben11 on 14 Jul 2014
To manually set the x and y-limits of an axes you can use this command:
set(handles.axes1,'XLim',[0 300],'YLim',[0 300]);
Also what do you mean by "set a patch to axes2"? I would say:
axes(handles.axes2);
...draw the patch object
Is it what you mean? If not please add a bit more details :)
  1 Comment
Matt
Matt on 15 Jul 2014
Hi Ben,
if I put in this code:
axes(handles.axes1);
set(ConveyorPatch, 'xdata', xCoordinates, 'ydata', yCoordinates);
but it still plots the patch on axes2 (which is the one on the left, see the first image)

Sign in to comment.


Matt
Matt on 15 Jul 2014
Hi Ben,
I'm still having the same problem. First, why does the size of my axes change when I hit "Run Figure?" (see the first two images above).
Secondly, set(handles.axes1,'XLim',[0 300],'YLim',[0 300]); makes the axis enormous, which I think was why it disappeared on me? For instance, If I do
set(handles.axes1, 'XLim', [0 2], 'YLim', [0 3]);
I go from the second image (above) to this:
I want axes1 to remain the same size, and for the x and y min and max to be set.
Thanks.
  2 Comments
Ben11
Ben11 on 15 Jul 2014
Ok maybe the axes resizing is due to the units used which may be different between axes. For instance are you sure all the axes are in "pixels" units? It might also be that their "xlimmode" or "ylimmode" properties are set to auto instead of manual; it once happened to me so that would be my guess.
Otherwise could you post a bit of code from your pushbutton "Run Figure"? That would help a lot to diagnose the problem better.
Thanks!
Matt
Matt on 15 Jul 2014
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
%axes(handles.axes1);
Z = zeros(6, 6);
set(handles.uitable1,'Data',Z)
A =cell(6, 5);
A(1:6, 1) = {'X'};
set(handles.uitable2,'Data',A)
run_flag = MainR(handles);
%*********************************************
%*********************************************
function MainR = MainR(handles)
set(handles.axes1, 'XLim', [0 250], 'YLim', [0 100]);
ColorData = [32 32 32];
xCoordinates = [201 203 208; 201 203 208; 203 205 210; 203 205 210];
yCoordinates = [20 22 24; 70 70 70; 70 70 70; 20 22 24];
ConveyorPatch = patch(xCoordinates, yCoordinates, ColorData);
axes(handles.axes1);
set(ConveyorPatch, 'xdata', xCoordinates, 'ydata', yCoordinates);

Sign in to comment.

Categories

Find more on Data Exploration in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!