フィルターのクリア

How to change a cell table from numeric to string?

1 回表示 (過去 30 日間)
Adam Taher
Adam Taher 2015 年 5 月 19 日
編集済み: Stephen23 2016 年 3 月 6 日
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);

採用された回答

Walter Roberson
Walter Roberson 2015 年 5 月 19 日
Use the property inspector on the uitable to set the ColumnFormat property to 'string'.
  1 件のコメント
MM BS
MM BS 2016 年 3 月 5 日
I have the same problem but I dont use Guide : I do it manully (directly) :
a={};
for i=1:10
a{i,5}=true;
end
h = uitable('data',a, ...
'columnformat', {'numeric','char','logical',{'str1','str2'},'logical'}, ...
'columneditable',true);
What I can do to impose to matlab to recongnize the string when it's a string format on the culmn?

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by