Dynamic grid images in MATLAB

I am working on creating a GUI in Matlab using GUIDE. However, I'm not quite sure how to do this, and was looking for some tips / advice.

Problem

I want to open a directory and display all the images in this directory in the GUI, if one is selected. However, since I will never know exactly how many images are, I’m not quite sure how to do this in the GUI.

Essentially, I want to open the directory and all the images that will be displayed on the grid in a graphical interface similar to the text in iphoto .

Current code

Currently, I can open the directory in order and get all the necessary information as follows:

directory = uigetdir(pwd, 'Directory Selector'); files = dir(fullfile(directory, '*.jpg')); strcat(strcat(directory, '/') , files.name) %outputs each file location 

I'm just not sure how to translate this information into a graphical interface without writing numerous .axes1 descriptors. I understand that since I know this information, I could iterate over them, but would not need to create axes to begin with?

+1
source share
2 answers

You probably don't want to do this with separate controls - the reason is that MATLAB will have to display each, which will be slow if there are a lot of images in the directory. Obviously, you can only display a certain number of images on the screen at a time. You will also have to write your own scroll code (or some kind of pagination control).

If you have MATLAB> R2008, you can put images in uitable cells using HTML:

 % Example for a control with a 'String' property set(handles.myControl, 'String', '<html><b>Logo</b>: <img src="http://UndocumentedMatlab.com/images/logo_68x60.png"/></html>'); 

See also this post and this undocumented MATLAB page .

Another option: use common ListView controls on Windows.

An easier way to do this is to have one image and a list of files; example here

+2
source

You can add components to the graphical interface pprogrammatically. There is more detailed information here .

Each new axis can be added something like this:

 ah = axes('Parent',hObject,'Position',[left bottom width height]); 

where the left, bottom, width and height determine the size and position of the axes. You will need to reposition for each axis you create and track the axis handles.

0
source

Source: https://habr.com/ru/post/952701/


All Articles