How to change a cell table from numeric to string?

Hi, i'm creating a GUI on Matlab and I would like to add a table and be able with pushbuttons to add/delete rows and columns (working with callback functions). This part of my GUI works fine. But my cells are all numeric cells only, and when I write letters, it gives me "NaN". Can someone help? Here is the code:
% --- Executes on button press in pushbutton7.
% ADD ROW %
function pushbutton7_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton7 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data = get(handles.uitable, 'data');
data(end+1,:) = 0;
set(handles.uitable, 'data', data);
% --- Executes on button press in pushbutton8.
% ADD COLUMN %
function pushbutton8_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton8 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
data = get(handles.uitable, 'data');
data(:,end+1) = 0;
set(handles.uitable, 'data', data);
% --- Executes when entered data in editable cell(s) in uitable.
% ADD TABLE %
function uitable_CellEditCallback(hObject, eventdata, handles)
%hObject handle to uitable (see GCBO)
%eventdata structure with the following fields (see MATLAB.UI.CONTROL.TABLE)
%Indices: row and column indices of the cell(s) edited
%PreviousData: previous data for the cell(s) edited
%EditData: string(s) entered by the user
%NewData: EditData or its converted form set on the Data property. Empty if Data was not changed
%Error: error string when failed to convert EditData to appropriate value for Data
% handles structure with handles and user data (see GUIDATA)
data = get(hObject,'data');
display(data);

3 件のコメント

Guillaume
Guillaume 2015 年 5 月 15 日
編集済み: Guillaume 2015 年 5 月 15 日
Instead of putting a blank line between each lines of code, just put two spaces before each line. That will format the lines as code and will be a lot more readable. Click on the (?) Help button to learn all about the formatting options available.
This is a lot more readable
Than
This
Stephen23
Stephen23 2015 年 5 月 15 日
編集済み: Stephen23 2015 年 5 月 16 日
@ Adam Taher: please do one of these:
  • format the code (you can use the {} Code button just above the textbox, and please remove the blank lines too!.
  • delete the code from the text, and upload the file using the paperclip button. You will then need to push Choose file and Attach file.
Adam Taher
Adam Taher 2015 年 5 月 15 日
i'm sorry, i'm new to this. First when I typed it, the preview showed me something even worse, I had to put lines for that. Hopefully now is better.

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

回答 (1 件)

Walter Roberson
Walter Roberson 2015 年 5 月 15 日

0 投票

You are using GUIDE. Go into the Properties for the uitable and set the 'ColumnFormat' to 'char' for all of the columns you want to now be strings.

1 件のコメント

Adam Taher
Adam Taher 2015 年 5 月 15 日
There is no 'char' format. There is 'let matlab choose', 'numeric', 'text', 'logical', 'choice list' and 'custom'. I suppose you mean 'text', but even this one doesn't work. Neither 'let matlab choose'

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

カテゴリ

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

質問済み:

2015 年 5 月 15 日

編集済み:

2015 年 5 月 16 日

Community Treasure Hunt

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

Start Hunting!

Translated by