フィルターのクリア

Creating uitable with multiple data types

7 ビュー (過去 30 日間)
Bryan Wilson
Bryan Wilson 2016 年 11 月 16 日
コメント済み: Walter Roberson 2016 年 11 月 17 日
I have a table that I need to open as a uitable. The original table has both character arrays and numeric variables. I get the following error when creating the uitable, .
Cannot concatenate the table variables _____ and ____, because their types are double and cell.
This isn't my exact code, but illustrates my problem...
%Build Table
SectionID = {'A';'B';'C';'D'};
Description = {'First';'Second';'Third';'Fourth'};
Measurement1 = [5.2;5.0;5.0;5.8];
Measurement2 = [10;11;15;10];
T = table(SectionID,Description,Measurement1,Measurement2);
%Set up figure
handles.fig = figure('Position',[400,400,500,190]);
handles.T = T;
%UI Table - TEXT ONLY - WORKS
uitable(handles.fig,'Data',handles.T{:,[1,2]},'ColumnWidth',{100},...
'ColumnName',handles.T.Properties.VariableNames([1,2]),...
'Position',[20,20,450,150]);
%UI Table - NUMERIC ONLY - WORKS
uitable(handles.fig,'Data',handles.T{:,[3,4]},'ColumnWidth',{100},...
'ColumnName',handles.T.Properties.VariableNames([3,4]),...
'Position',[20,20,450,150]);
%UI Table - TEXT AND NUMERIC - DOES NOT WORK
uitable(handles.fig,'Data',handles.T{:,:},'ColumnWidth',{100},...
'ColumnName',handles.T.Properties.VariableNames(:),...
'Position',[20,20,450,150]);

採用された回答

dpb
dpb 2016 年 11 月 16 日
編集済み: Walter Roberson 2016 年 11 月 16 日
Indeed, the error message is right--"you can't do that!" of trying to concatenate cell array and non-cell array values.
You'll have to convert the table into a cell array to pass to uitable; it isn't table-aware so can't use the table directly, either.
I don't have release that includes the table class, but I'd think table2cell(T) would be just the ticket here...see table2cell()
  3 件のコメント
Bryan Wilson
Bryan Wilson 2016 年 11 月 17 日
What confuses me is I don't know why it's trying to concatenate at all. For the record...here's the code that DOES work.
%Build Table
SectionID = {'A';'B';'C';'D'};
Description = {'First';'Second';'Third';'Fourth'};
Measurement1 = [5.2;5.0;5.0;5.8];
Measurement2 = [10;11;15;10];
T = table(SectionID,Description,Measurement1,Measurement2);
%Set up figure and UI Table
handles.fig = figure('Position',[400,400,500,190]);
handles.T = table2cell(T);
uitable(handles.fig,'Data',handles.T(:,:),'ColumnWidth',{100},...
'ColumnName',T.Properties.VariableNames(:),...
'Position',[20,20,450,150]);
Walter Roberson
Walter Roberson 2016 年 11 月 17 日
For a table, the notation handles.T{:,:} is equivalent to horzcat() of all of the T{:,1}, T{:.2}, ... and for that to work they need to be compatible data types. T{:,:} notation is for extracting to array, not for extracting to cell.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by