How to add additional rows to uitable?

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 日

0 投票

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 日
Yes, I found out this workaround myself, but I think it is not at all elegant. It includes two more buttons etc.
If there would be a keyboard callback (which I could not found) that would be a really nice solution. Why there is no such a callback? Then you might use "insert", "delete", "down arrow" etc keyboard keys instead of adding more and more button objects to the window where uitable is sitting. In 'Variables window' it is solved, so there should be a hidden solution somewhere in the 'deep MATLAB'.
So I can accept your answer as a workaround but I do not like it -:)
Mario Malic
Mario Malic 2021 年 3 月 8 日
編集済み: Mario Malic 2021 年 3 月 8 日
What about KeyPressFcn, 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.
Edit: if you want only to add the row only at the end of the table, then KeyPressFcn will be sufficient,
Csaba
Csaba 2021 年 3 月 8 日
In my help there is no KeyPressFcn property. I have 2019b. Do you know when it was introduced? The reference you have given says it is valid for 2020b, but I do not see when it was introduced.
Csaba
Csaba 2021 年 3 月 8 日
Mario Malic
Mario Malic 2021 年 3 月 8 日
編集済み: Mario Malic 2021 年 3 月 8 日
I can't see when are callbacks added, as this information is not added in Release Notes
You can assign a KeyPressFcn to uifigure. If you only have one uitable that you want to add the rows into, you're can pass its handle to the function, if you have few, then you can use CurrentObject property of uifigure to determine on which table you want to add the rows.
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 件)

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

リリース

R2019b

タグ

質問済み:

2021 年 3 月 8 日

コメント済み:

2021 年 3 月 8 日

Community Treasure Hunt

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

Start Hunting!

Translated by