MATLAB Answers

How do I change the dimensions of a UItable through edit field boxes?

조회 수: 1(최근 30일)
Pritesh Patel
Pritesh Patel 2021년 6월 1일
답변: Reshma Nerella 2021년 6월 18일
I am wanting to use the edit field boxes to change the rows and columns of the UI table I have in my GUI. I have set the first edit field box to the number of rows (labeled n) and the second field box for the number of columns (labelled m). I have a pushbutton labelled insert that should take the values of n and m and create the table from those values.
However I get this error "The class handle has no Constant property or Static method named 'UItable'." when I use handles to refer to the table. Is there a mistake that I have done to refer to the table incorrectly?
Below is the code I have on the pushbutton callback.
Nrows = app.n; %app.n from edit field box 1 callback
Ncolumns = app.m; %app.m from edit field box 2 callback
set(handle.UItable,cell(Nrows,Ncolumns)); %error occurs here - most likely this entire line is wrong
Any help would be appreciated.

답변(1개)

Reshma Nerella
Reshma Nerella 2021년 6월 18일
Hi,
I understand that you want to take the number of rows and columns as inputs from edit boxes and create a table of that size.
Here's an example
rows = app.EditField.Value;
cols = app.EditField2.Value;
vars = repmat("double",1,cols); % Variable types for all columns, I chose double for example.
t = table('Size',[rows,cols],'VariableTypes',vars);
app.UITable.Data = t;
When you do it this way, you should also be mentioning about the variable type for each column while creating variable 't'.
Hope this helps!

태그

Community Treasure Hunt

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

Start Hunting!

Translated by