Increasing number of columns in UITable runs slow on command.

3 visualizaciones (últimos 30 días)
Jeremy Falcon
Jeremy Falcon el 4 de Abr. de 2020
Respondida: Image Analyst el 4 de Abr. de 2020
I created a UITable with 6 default columns in the design view. My code allows user to switch two radio button entities. The first case reduces the number of columns to 5 and the second case increases the number of columns back to 6. The code works when I run (f5) case 1 or case 2 from startup. However, the app freezes when I switch from case 1 to case 2. But, when I debug and run by step, there is no error or freezing. How do I solve the problem of the app freezing when I increase the number of columns in UITable. That is, when I switch from case 1 to case 2.
The codes are,
switch button group
case 1
%create first row in table
u = {1 0 0 0 0 0}
app.UITable.Data = u
%create subsequent rows. num is a variable with numerical value input by user
for i = 2:num
n = {i 0 0 0 0 0};
app.UITable.Data = [u;n];
u = app.UITable.Data;
end
%delete the 6th column
app.UITable.Data(:,6) = [];
u = app.UITable.Data;
%rename column heading names
app.UITable.ColumnName = {'a'; 'b'; 'c'; 'd'; 'e'}
end
case 2
%create first row in table
u = {1 0 0 0 0 0}
app.UITable.Data = u
%create subsequent rows. num is a variable with numerical value input by user
for i = 2:num
n = {i 0 0 0 0 0};
app.UITable.Data = [u;n];
u = app.UITable.Data;
end
%rename column heading names
app.UITable.ColumnName = {'a'; 'b'; 'c'; 'd'; 'e'; 'f'}
end
end

Respuestas (1)

Image Analyst
Image Analyst el 4 de Abr. de 2020
What is the value of num?
And why do you have an end after the first case block? That end closes off the switch statement. Then case 2 is left without a switch statement. I'm surprised it even ran. I'd think you should have gotten a syntax error.
You can put fprintf() in there at key locations to tell what place you're getting to during runtime.
fprintf('Now I am about to enter the case 1 block of the switch statement.\n');
fprintf('Now I am about to enter the for loop.\n');
fprintf('Now I just finished the for loop.\n');
etc.

Categorías

Más información sobre App Building en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by