How to adjust the position and size of preview image in custom preview window?

6 views (last 30 days)
Hello,
I'm following this guide: http://se.mathworks.com/help/imaq/previewing-data.html where I'm creating my own gui for the video preview.
I'm having problems when adjusting the size of the gui when the code is running. The image preview stretches relatively with the preview window, which I don't wan't it to do.
On the guide there's code which should fix the problem:
% Specify the size of the axes that contains the image object
% so that it displays the image at the right resolution and
% centers it in the figure window.
figSize = get(hFig,'Position');
figWidth = figSize(3);
figHeight = figSize(4);
gca.unit = 'pixels';
gca.position = [ ((figWidth - imWidth)/2)...
((figHeight - imHeight)/2)...
imWidth imHeight ];
But it does not seem to do anything on my Matlab R2013a. There is no difference if I comment or not this part of the code. I also tried the full example code on Matlab R2015a with the same results. The gca part doesn't seem to do anything.
Is there something missing? I'm able to do uipanels in the preview window with fixed positions and resolutions:
video_window = uipanel('Title','video','FontSize',10,...
'BackgroundColor','white',...
'Units', 'Pixels',...
'Position',[1 1 640 480]);
% x-position, y-position, width, heigth
But how could I then force the preview image to this panel? Buttons can be forced by specifying them with " 'parent', video_window, " initialising commands.
Any help with this matter is appreciated. Thank you in advance.
Zzzz.

Answers (1)

Adam Hug
Adam Hug on 2 Jul 2015
The "gca" commands all apply to the current axis in the current figure. Make sure that the axis you are trying to modify is indeed the current axis before applying these commands. See the following link for more information:

Community Treasure Hunt

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

Start Hunting!