Azzera filtri
Azzera filtri

App designer: load cell array components to listbox

20 visualizzazioni (ultimi 30 giorni)
Hello,
I am trying to create an UI App that creates a list of files (cell array) and displays it in a list box. This would be very helpfull so that the user can see the list of files they want to further analyse and maybe delete or add files.
I am not experienced with App designer, so I am afraid I am missing some important component in the code.
classdef SPT_GUI_v1 < matlab.apps.AppBase
%... Properties that correspond to app components ...
% Global variables
properties (Access = public)
allfiles % contains the list of selected trackmate files
end
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: AddButton
function AddButtonPushed(app, event)
app.allfiles = cell(0,1);
[filename,path] = uigetfile('*.*','All Files (*.*)',...
'Select files','MultiSelect','on');
filename = cellstr(filename);
path = cellstr(path);
filePattern = fullfile(path,filename);
NFiles = sum(cellfun('size',filename,1));
if NFiles > 1
filePattern = filePattern.';
end
app.allfiles = [app.allfiles;filePattern];
end
% Value changed function: TrackFilesListBox
function TrackFilesListBoxValueChanged(app, event)
app.allfiles = app.TrackFilesListBox.Value;
end
% ... Component initialization ...
end
end
Thank you for your help!!

Risposta accettata

Cris LaPierre
Cris LaPierre il 8 Giu 2020
I'm not sure what you are picturing as your end result, so I'll start simple. The following code will populate a list box with the files selected using uigetfile. This code would go inside your pushbutton callback function.
[filename,path] = uigetfile('*.*','All Files (*.*)',...
'Select files','MultiSelect','on');
app.filePattern = fullfile(path,filename);
app.ListBox.Items = app.filePattern;
  2 Commenti
Jessica Angulo Capel
Jessica Angulo Capel il 9 Giu 2020
Thanks! Then, if I understood well I should store the list box items in the pushbutton callback function and not in the list box callback function.
Cris LaPierre
Cris LaPierre il 9 Giu 2020
You should store them as a property of the app. Load and add them to the app structure in the pushbutton callback. Once there, you can access them from any callback. The list box callback will execute when the item selected in the list box changes. So the listbox callback function should contain the code you want to execute when that happens.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Dialog Boxes in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by