uitable callback: replace cell in a cell array with 'char' string value gives NAN not 'text'

I have a mat file with a cell array with various numbers and text. I load this into a uitable and give the user the opportunity to change the values of certain cells then it auto saves to csv (cell2csv). This works fine for pop-up and numeric columnn formats, but if the column format is set at 'char' 'ABC' it appears as NaN in the table/cell array.
My callback is basically: datacellarray(event.Indices) = {event.NewData}
I've tried [] {} () in various positions and tried inputting different things in the uitable cell and setting the uitable column format to no avail. I am sure it is something completely obvious but I can only bang my head against the wall for so long. Any help/insight is greatly appreciated.

5 件のコメント

G
G 2011 年 8 月 29 日
Ok, I may be doing something differently.
I have a uitable in a gui.
set(gTable,'ColumnFormat',guidata.gTableColFormat)
guidata.gTableColFormat = {'numeric',guidata.popup,'char'};
G
G 2011 年 8 月 29 日
Thanks for you help so far.
I can't use (event.Indices(1),event.Indices(2)) because the uitable and the datacellarray are not equal. I need to re-position a bit.
guidata.datacellarray(event.Indices(1)+1,n) = {event.NewData};
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 29 日
That's fine. What is your MATLAB version?
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 29 日
In earlier release, if you type help uitabel, you will see
This function is undocumented and will change in a future release
G
G 2011 年 8 月 29 日
Thanks so much for your patience. I found the error buried in table construction. The text column was off by one. It was my indexing.
Cheers.

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

 採用された回答

Fangjun Jiang
Fangjun Jiang 2011 年 8 月 29 日

1 投票

try datacellarray(event.Indices(1),event.Indices(2)) = {event.NewData};

9 件のコメント

G
G 2011 年 8 月 29 日
Thanks for the reply.
I just tried this with 'char' as the uitable ColumnFormat and got:
"??? Conversion to cell from double is not possible."
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 29 日
Put a break point at that line and debug it. What is the value of event.NewData?
G
G 2011 年 8 月 29 日
event.NewData NaN <1x1 double>
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 29 日
See my updated answer. I tried. If the column format is 'Numeric' and you enter a string like 'abc', it will give NaN. But if the column format is 'Text', it shouldn't have problem. Please double check.
G
G 2011 年 8 月 29 日
I should provide more information as maybe it is my indexing?
My data is in a structure and the indexing gets moved a bit to accommodate the differences between what in in the datacellarray and what is actually shown in the uitable. shifted right one column and n being the proper column based on a strncmp in the first header row.
guidata.datacellarray(event.Indices(1)+1,n) = event.NewData;
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 29 日
What version of MATLAB are you using? I tried on R2010b. The choices for column format are: 'Let MATLAB Choose','Numeric','Text','Logical','Choice List...','Custom...'. I don't see 'char'.
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 29 日
Your indexing seems fine. You need to have the {} at the right hand side. I think it's probably due to column format. Double check the column format for that column.
G
G 2011 年 8 月 29 日
It appears I can only use 'char' as a ColumnFormat.
"ColumnFormat definitions must be either 'numeric', 'logical', 'char', or be a popupmenu definition"
I am getting the feeling it is something deeper.
Fangjun Jiang
Fangjun Jiang 2011 年 8 月 29 日
Run the two lines below and then try to change the value. In column 1, if you try to type in 'abc', it will become NaN. In column 2, you can type in anything.
a={1 'a' true};
h=uitable('data',a,'columnformat',{'numeric','char','logical'},'columneditable',true)

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

その他の回答 (0 件)

カテゴリ

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

質問済み:

G
G
2011 年 8 月 29 日

Community Treasure Hunt

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

Start Hunting!

Translated by