matlabmatlab-app-designer

Add jpg file names to a list box and select one for watching - Matlab


How can read a selected jpg from this list box and view it in an axes?

    function selectFolderButtonPushed(app, event)
        app.selectedPath = uigetdir();
        jpgFileInfo = dir(fullfile(app.selectedPath, '*.jpg'));
        app.jpgListBox.Items =  {jpgFileInfo.name}';
    end


    function loadimageButtonPushed(app, event)
        imageSelected = imread(......);
        imshow(imageSelected, app.imageAxes);
    end

Solution

  • I hope it helps:

    function SelectFolderButtonPushed(app, event)
                app.selectedPath = uigetdir();
                jpgFileInfo = dir(fullfile(app.selectedPath, '*.jpg')) 
                app.jpgListBox.Items =  {jpgFileInfo.name}'; 
            end
     
            function loadimageButtonPushed(app, event)
                selectedFileName = app.jpgListBox.Value;
                selectedPath = app.selectedPath;
                imageSelected =strcat(selectedPath, "\", selectedFileName)
                imshow(imageSelected,'Parent',app.imageAxes); 
            end