App designer: load cell array components to listbox

13 ビュー (過去 30 日間)
Jessica Angulo Capel
Jessica Angulo Capel 2020 年 6 月 8 日
コメント済み: Cris LaPierre 2020 年 6 月 9 日
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
Jessica Angulo Capel 2020 年 6 月 9 日
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 Center および File ExchangeApp Building についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by