フィルターのクリア

add a cell array in double for one more column in uitable

3 ビュー (過去 30 日間)
Venkat Ta
Venkat Ta 2019 年 7 月 15 日
編集済み: Adam Danz 2019 年 7 月 15 日
Hi,
I would like to add units column in the 4th column but it's in cell form and join_ all is the double attribute array, it doesn't allow
good ideas really appreciated
Thanks
Best regards
Venkat
%% Start
clear all; close all; clc;
rnames = {'<html><font size=+1>First','<html><font size=+1>Second','<html><font size=+1>Third','<html><font size=+1>fourth','<html><font size=+1>fifth'}; % These are your row names
cnames = {'<html><font size=+1>X=data','<html><font size=+1>Y-Data','<html><font size=+1>[Z-Data]'}; % for bold <h1>World</h1>
x = [38;43;38;40;49];
y = [71;69;64;67;64];
z = [176;163;131;133;119];
Units = {'mm/N';'1/N';'1/Nmm';'1/Nmm^2';'1/Nmm^3';};
join_all=[x y z];
fig = figure('Position', get(0, 'Screensize'),'Name','Numbers');
t = uitable(fig,'Data',join-all,'ColumnName',cnames,...
'RowName',rnames,'Position',[20 20 1050 800] ,'FontSize',20); %,'Units','Normalized','Position',[0 0 1 1],'fontSize',19
set(t,'ColumnWidth',{100})
table_extent = get(t,'Extent');
set(t,'Position',[1 1 table_extent(3) table_extent(4)])
figure_size = get(fig,'outerposition');
desired_fig_size = [figure_size(1) figure_size(2) table_extent(3)+15 table_extent(4)+65];
set(fig,'outerposition', desired_fig_size);

採用された回答

the cyclist
the cyclist 2019 年 7 月 15 日
編集済み: the cyclist 2019 年 7 月 15 日
Convert the numeric array into a cell array before concatenating. Then use the cell array as the input to the uitable command.
%% Start
clear all; close all; clc;
rnames = {'<html><font size=+1>First','<html><font size=+1>Second','<html><font size=+1>Third','<html><font size=+1>fourth','<html><font size=+1>fifth'}; % These are your row names
cnames = {'<html><font size=+1>X=data','<html><font size=+1>Y-Data','<html><font size=+1>[Z-Data]','<html><font size=+1>[unit-Data]'}; % for bold <h1>World</h1>
x = [38;43;38;40;49];
y = [71;69;64;67;64];
z = [176;163;131;133;119];
Units = {'mm/N';'1/N';'1/Nmm';'1/Nmm^2';'1/Nmm^3';};
join_all=[num2cell([x y z]), Units];
fig = figure('Position', get(0, 'Screensize'),'Name','Numbers');
t = uitable(fig,'Data',join_all,'ColumnName',cnames,...
'RowName',rnames,'Position',[20 20 1050 800] ,'FontSize',20); %,'Units','Normalized','Position',[0 0 1 1],'fontSize',19
set(t,'ColumnWidth',{100})
table_extent = get(t,'Extent');
set(t,'Position',[1 1 table_extent(3) table_extent(4)])
figure_size = get(fig,'outerposition');
desired_fig_size = [figure_size(1) figure_size(2) table_extent(3)+15 table_extent(4)+65];
set(fig,'outerposition', desired_fig_size);
I also fixed the fact that you wrote join-all instead of join_all in the uitable command.

その他の回答 (1 件)

Adam Danz
Adam Danz 2019 年 7 月 15 日
編集済み: Adam Danz 2019 年 7 月 15 日
data = [num2cell(join_all), Units]; % <--- cell array
t = uitable(fig,'Data',data);

カテゴリ

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

タグ

製品


リリース

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by