Concatenate rows into a table using a for loop with app designer

조회 수: 13 (최근 30일)
Here I have an app designer call back function where when the user selects 'Instant Charge' in the drop down menu and clicks the button, it will output all the values (a,b) in a table. Going from row to row, I am having trouble with concatenating a new row to the table. The code is set up in a for loop so that it indexes the value in array a and array b but once that row is outputted in the table, I would like the next index of a and b values to be stored in the second row of the table, and so on. In this example, there are about 300 rows that need to be added to the table. May I get some assistance with concatenating new rows to the same table. Thank you for your help.

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 2월 10일
Note that if you need to update the content of the table, then you should use one of these approaches:
(1) Update the table:
A = randi([-10, 10], 3, 1);
B = table(A);
for ii = 1:10
B.A(ii+3) = randi([-10, 10],1);
end
B
B = 13×1 table
A ___ -9 -2 -10 2 10 -8 2 -2 -5 5 -1 1 1
(2) Update the table:
% OR
K = [];
M = table(K);
for ii = 1:10
M{ii,:} = randi([-10, 10],1);
end
M
M = 10×1 table
K __ 7 5 -7 4 -4 4 -4 6 -2 3
(3) Concatenate the tables with the same variable name:
P = randi([-10, 10],1);
W = table(P);
for jj = 1:5
P = (randi([-10,10],1));
U = table(P);
W = [W; U];
end
W
W = 6×1 table
P __ 5 -1 9 8 4 5
  댓글 수: 1
Ratanjot
Ratanjot 2023년 2월 10일
편집: Ratanjot 2023년 2월 10일
I used option 2 to concatenate the rows in the same UITable and it works. Thanks. What would I do if I am trying to output multiple columns at a time. In the end, this could become a table with 100 rows and 10 columns. There would be something that needs to be done within the for loop. When I try to add a column using a comma I get the error, "Invalid expression. When calling a function or indexing a variable, use parentheses. Otherwise, check for mismatched delimiters.". Can I get some help with this on how to combine columns together.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 2월 10일
Maybe you can try this approach:
for jj=1:5
for ii = 1:10
M(jj,ii) = randi([-10, 10],1);
end
end
M_tab = array2table(M)
M_tab = 5×10 table
M1 M2 M3 M4 M5 M6 M7 M8 M9 M10 __ ___ __ ___ __ ___ __ __ __ ___ 1 2 -3 -5 -2 -3 9 -7 10 -7 -8 -10 7 7 10 -4 10 6 -3 10 -1 -10 8 -4 3 -2 1 10 -4 -4 5 -5 -8 4 -8 -4 6 -7 3 -9 -2 9 -6 -10 -8 -10 -2 -9 7 3

카테고리

Help CenterFile Exchange에서 Develop Apps Using App Designer에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by