App designer: load cell array components to listbox

조회 수: 7 (최근 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 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