Hi
I'm new to matlab. Currently I'm working with GUI. So I developed a code to visible a table to gather user inputs. That uitable has 2 columns. Number of rows is a user defined value n. Column 1 must have predefined values and column 2 must gather user input data to an array. I want to assign values from 1 to n for column 1 of uitable. So I tried with a for loop. This is my code.
n = str2num(get(handles.N,'String')); % get number of stories from user
set(handles.table1,'visible','on')
ndata = cell(n,2);
set(handles.table1, 'data',ndata);
for i=1:1:n
set(handles.table1(i,1),'String',i);
Following error occurred.
The name 'String' is not an accessible property for an instance of class 'uitable'
Can anyone tell me what should be the modification here?
Thank You

1 件のコメント

Adam
Adam 2017 年 7 月 4 日
Did you read the help documentation for uitable? If not why not?, if so why are you trying to assign 'String' in a table? 'Data' is the property you should be setting.

サインインしてコメントする。

 採用された回答

Jan
Jan 2017 年 7 月 4 日
編集済み: Jan 2017 年 7 月 4 日

1 投票

This is based on pure guessing, isn't it? Neither handles.table1(i,1) nor the 'String' property is meaningful. Did you read the documentation already?
doc uitable
You cannot set a 'String' property to a number. Defining the 'data' was the right way already:
ndata = cell(n,2);
for k = 1:n
ndata{k,1} = k;
end
set(handles.table1, 'data', ndata);

3 件のコメント

Ishanka M
Ishanka M 2017 年 7 月 5 日
You are right sir. Thank you very much
Ishanka M
Ishanka M 2017 年 7 月 5 日
I have another issue sir. I need to get values from user for the second column of above uitable and I need to assign those values in a array. How to do that sir? Thank You very much
Jan
Jan 2017 年 7 月 5 日
It depends on what "get values from the user" and "assign values in an array" means.How do you want to get the values? Through a GUI, input, from a function or just by editing the uitable? When and where should the values be assigned to an array?

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Programming についてさらに検索

質問済み:

2017 年 7 月 4 日

コメント済み:

Jan
2017 年 7 月 5 日

Community Treasure Hunt

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

Start Hunting!

Translated by