App designer: load cell array components to listbox

20 次查看(过去 30 天)
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!!

采纳的回答

Cris LaPierre
Cris LaPierre 2020-6-8
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 个评论
Jessica Angulo Capel
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 2020-6-9
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dialog Boxes 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by