set count numbers of rows in a uitable
조회 수: 7 (최근 30일)
이전 댓글 표시
Hi,
I'm trying to modify the first column number for each row( 1 2 3 ...) in an uitable based of each entry from another uitable:
D=get(handles.uitable1,'Data');%GETTING DATA FROM FIRST TABLE
Index=get(handles.uitable1,'UserData');
a = D(Index.Indices(:,1), :);
old_data=get(handles.uitable4,'Data'); %GETTING OLD DATA FROM SECOND TABLE
data_azi = datetime;
data_azi.Format = 'MM.dd.yyyy';
a = array2table(a);
a.a1 = 1;
a.a4 = a.a2;
a.a2 = char(data_azi);
a.a2 = {a.a2};
a = table2cell(a);
new_data = [old_data; a];
new_data = array2table(new_data);
numarnou = height(new_data);% GET HEIGHT OF OLD AND NEW TABLE
new_data.new_data2 = numarnou;% MODIFY THE RESULT OF ROWS HEIGHTS IN FIRST COLUMN
new_data.new_data2 = {new_data.new_data2};
new_data = table2cell(new_data);
set(handles.uitable4, 'Data',new_data); %SETTING DATA FROM FIRST TABLE
The error:
To assign to or create a variable in a table, the number of rows must match the height of the table.
Where am I wrong?
댓글 수: 6
dpb
2022년 6월 6일
new_data = [old_data; a];
You've catenated more data onto the existing from uitable1 so the height is the total of both tables.
The uitable object is not dynamically resized; I've not used it extensively, but I think the only way to add data entails recreating a new table. Seems klunky, but I've not seen anything that implies there is an addrow functionality.
채택된 답변
Cristian Martin
2022년 6월 6일
댓글 수: 2
dpb
2022년 6월 6일
It's OK. I now recall I had seen that before but I just couldn't recall it before...I hadn't used the uitable enough to recall it, but I shoulda'.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!