Matlab App very slow

Hi everyone.
I created a simple App in Matlab, which unfortunately is very slow. Consider you have a document consisting of a couple of sentences, given in a sting array.
The app now lists the individual sentences one below the other. For each sentence there are 18 buttons with which you can classify the sentences. If, for example, a document has 3 sentences, the total number of buttons is 54. If i run the app with 19 sentences, it takes ~45 seconds until I can use it. It also reacts very slow to changes on the window size.
What am i doing wrong? Is it a problem that I have too many buttons?
Thank you in advance for your help!

4 Comments

19x18 is quite a decent amount of buttons, which makes it not a simple app. Did you create a StartupFcn that does something when you start your program? If yes, try commenting some of the code and see if it will load faster. Maybe you have some inefficiency in your code.
Hi Mario,
thank you for answering. Yes, I created a StartupFcn which calls the function "createPanel". This function is defined as follows:
function app = createPanel(app)
% Read actual document
doc_act=app.Documents{app.Index};
% Update Panel
Panel = uipanel(app.GridLayout);
Panel.Title = "Sentences of Document "+app.Index;
Panel.Layout.Row = [3 11];
Panel.Layout.Column = [1 7];
% Create panelGrid
panelGrid = uigridlayout(Panel,[3*length(doc_act),9]);
panelGrid.RowHeight=repmat({60,18,18},1,length(doc_act));
panelGrid.ColumnWidth = ['0.3x',repmat({'1x'},1,9)];
% Create text fields and buttons
for sentidx=1:length(doc_act)
% Create Text for Sentencenumber
panelText = uitextarea(panelGrid);
panelText.Value = string(sentidx);
panelText.Layout.Row = [1+3*(sentidx-1),3+3*(sentidx-1)];
panelText.Layout.Column = 1;
panelText.FontSize=20;
panelText.FontWeight='bold';
panelText.HorizontalAlignment='center';
panelText.Editable='off';
% Create panelText
panelText = uitextarea(panelGrid);
panelText.Value = doc_act{sentidx};
panelText.Layout.Row = 1+3*(sentidx-1);
panelText.Layout.Column = [2 10];
panelText.Editable='off';
% Create Buttonrow 1
for buttonidx=1:length(app.Buttonnames1)
Button = uibutton(panelGrid, 'state');
Button.Text = app.Buttonnames1(buttonidx);
Button.Layout.Row = 2+3*(sentidx-1);
Button.Layout.Column = buttonidx+1;
Button.FontSize=9;
end
% Create Buttonrow 2
for buttonidx=1:length(app.Buttonnames2)
Button = uibutton(panelGrid, 'state');
Button.Text = app.Buttonnames2(buttonidx);
Button.Layout.Row = 3+3*(sentidx-1);
Button.Layout.Column = buttonidx+1;
Button.FontSize=9;
end
end
panelGrid.Scrollable='on';
end
  • The "Documents" property of the app simply a cell array containing the documents. A document it self is again a cell array containing sentences as strings.
  • The "Index" property of the app is an integer representing the number of the document which should be displayed.
  • The code first creates a panel with a gridlayout. If n is the number of sentences of the actual document, then the grid has n*3 rows (per Sentence one row for the textarea for that sentence, one row for the first nine buttons and one row for the second nine buttons)
  • I use for loops to fill the grid with sentences and buttons, I think it is quite straight foreward
Please note that I added a picture of how the app looks like at the moment. I only shared the code for the panel (the box below "Setences of Document 2"), but I dont think that the rest of the app is problematic. The idea is to click through documents and label every sentence in these documents according some classes.
Again, thank you for your help!
App and the code looks neat! I don't think it's the number of components that are problematic anymore as I've taken your example and created 50 buttons and app was ready in a second or two.
I'd suggest you to check the part of the code that relates to loading the document and processing its sentences, use profiler like this
profile on;
NameOfApplication
profile viewer;
In the graph you'll see your startupFcn, by clicking on the bars you can get more information.
Thank's again for your answer! The idea using the profiler is great, that helped a lot!

Sign in to comment.

Answers (0)

Categories

Find more on Environment and Settings in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!