How to add additional rows to uitable?

조회 수: 74 (최근 30일)
Csaba
Csaba 2021년 3월 8일
댓글: Mario Malic 2021년 3월 8일
I have (X,Y) vextor pairs for storing spectral data. If someone wants to correct the vectors I make an uitable user input, where users can correct, replace etc. the data they have (uitable has two columns). Is there any easy way to add new rows (or columns??) to the existing uitable if the user wants to add some extra data not just correct the existing data?
I think it should be possible because in the variable window you can easily change the size of a variable just using the matrix where the variable is written, simply put a number to any matrix element. The variable size will immediately change and the missing values would be filled by zero. I would like to have something similar.

채택된 답변

Mario Malic
Mario Malic 2021년 3월 8일
편집: Mario Malic 2021년 3월 8일
Hey,
1st option:
KeyPressFcn callback, see UITable callbacks. Create a CellSelectedFcn callback first that saves selected cell in a property so you can access it from anywhere. Then with KeyPressFcn detect if button 'insert' is pressed, if yes, insert a row into the Data property of uitable.
If you want only to add the row only at the end of the table, then KeyPressFcn will be sufficient,
2nd option:
I have made a demo app for this purpose here. If you add the vector with any values to the component, it will expand
app.UITable.Data(end+1) = zeros(1, width(app.UITable.Data));
  댓글 수: 7
Csaba
Csaba 2021년 3월 8일
I have checked the handle of my uitable, and really there is a KeyPressFcn property (of course empty) which I was missing for long time and believing in help I did not check. Crazy me!!!! I will always check the handles in the future!
Anyway, thank you for your suggestion!!!! Please repeat your suggestion as an answer and I will accept it!
Mario Malic
Mario Malic 2021년 3월 8일
Great! You're welcome.
I have edited this answer.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by