フィルターのクリア

How to construct a table with several matrices

7 ビュー (過去 30 日間)
Lily
Lily 2012 年 9 月 26 日
Hi.
Is is possible to construct a table in MATLAB that contains four matrices? That is, if I were to have four matrices:
Sigma1 = [1 0.5; 0.5 1];
Sigma2 = [1 -0.5; -0.5 1];
Sigma3 = [0.4 1; 8.0 2.0];
Sigma4 = [8.0 2; 0.2 0.1];
Could I put this into a table that has two ColumnName and two RowName, but each "value "in the table is one Sigma matrix? Can you please help me?

採用された回答

Matt Fig
Matt Fig 2012 年 9 月 26 日
編集済み: Matt Fig 2012 年 9 月 26 日
The closest you can come is to put each element of each Sigma into the items in a popup.
Sigma1 = [1 0.5; 0.5 1];
Sigma2 = [1 -0.5; -0.5 1];
Sigma3 = [0.4 1; 8.0 2.0];
Sigma4 = [8.0 2; 0.2 0.1];
S1 = arrayfun(@(x) sprintf('%2.2f',x),Sigma1,'Un',0);
S2 = arrayfun(@(x) sprintf('%2.2f',x),Sigma2,'Un',0);
S3 = arrayfun(@(x) sprintf('%2.2f',x),Sigma3,'Un',0);
S4 = arrayfun(@(x) sprintf('%2.2f',x),Sigma4,'Un',0);
fh = figure('Position',[100 100 400 150],'menu','none');
dat = { S1{1},S2{1},S3{1},S4{1}};
columnname = {'Sigma1','Sigma2','Sigma3','Sigma4'};
columnformat = {S1(:).',S2(:).',S3(:).',S4(:).'};
columneditable = [true,true,true,true];
t = uitable(fh,'Units','pix','Position',...
[10 10 380 130], 'Data', dat,...
'ColumnName', columnname,...
'ColumnFormat', columnformat,...
'ColumnEditable', columneditable,...
'RowName',[]);
  2 件のコメント
Lily
Lily 2012 年 9 月 26 日
Thx, Yes I think this is the closest thing to want I'm trying to get :)
Image Analyst
Image Analyst 2012 年 9 月 26 日
Wow, very cool!

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

その他の回答 (4 件)

Azzi Abdelmalek
Azzi Abdelmalek 2012 年 9 月 26 日
編集済み: Azzi Abdelmalek 2012 年 9 月 26 日
A={sigma1,sigma2;sigma3,sigma4}
  2 件のコメント
Lily
Lily 2012 年 9 月 26 日
編集済み: Lily 2012 年 9 月 26 日
Do you know why I can't use the uitable for this code? Would you recomend some other table function?
f = figure('Position',[200 200 400 150]);
cnames = {'\Original \Sigma','\Sigma for N=100'};
rnames = {'\Sigma_1','\Sigma_2'};
t = uitable('Parent',f,'Data',A,'ColumnName',cnames,...
'RowName',rnames,'Position',[20 20 360 100]);
Image Analyst
Image Analyst 2012 年 9 月 26 日
Well, in your original post you said "table" and that is kind of ambiguous. A table could be a cell array/matrix, like Azzi (and I) initially thought, or it could be a uitable like you've now clarified in your comments. See my answer regarding uitable.

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


Thomas
Thomas 2012 年 9 月 26 日
Or you could form a 3D matrix; where each 3rd dimension is an individual Sigma matrix
Sigma1 = [1 0.5; 0.5 1];
Sigma2 = [1 -0.5; -0.5 1];
Sigma3 = [0.4 1; 8 2];
Sigma4 = [8 2; 0.2 0.1];
Sigma(:,:,1)=Sigma1;
Sigma(:,:,2)=Sigma2;
Sigma(:,:,3)=Sigma3;
Sigma(:,:,4)=Sigma4;
Sigma
  1 件のコメント
Lily
Lily 2012 年 9 月 26 日
編集済み: Lily 2012 年 9 月 26 日
If I use this, and by the why it's a brillant solution, I can't seem to use the uitable because it's a 3D soultion. What table function would be better to use? Below is my code for the uitable:
f = figure('Position',[200 200 400 150]);
cnames = {'\Original \Sigma','\Sigma for N=100'};
rnames = {'\Sigma_1','\Sigma_2'};
Sigma(:,:,1) = Sigma1;
Sigma(:,:,2) = Sigma3;
Sigma(:,:,3) = Sigma2;
Sigma(:,:,4) = Sigma4;
t = uitable('Parent',f,'Data',Sigma,'ColumnName',cnames,...
'RowName',rnames,'Position',[20 20 360 100]);

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


Babak
Babak 2012 年 9 月 26 日
mytable=cell(2,2);
mytable{1,1}=[1 0.5; 0.5 1];
mytable{1,2}=[1 -0.5; -0.5 1];
mytable{2,1}=[0.4 1; 8.0 2.0];
mytable{2,2}=[8.0 2; 0.2 0.1];
mytable % display it
  2 件のコメント
Lily
Lily 2012 年 9 月 26 日
THX :) Is it possible to display the mytable in to a inbuild table format? I would like to construct the like you would be able to in Word that is for (1,1) in the displayed table is result would appiear and so on?
Image Analyst
Image Analyst 2012 年 9 月 26 日
Babak - see her response to Tom. The "table" she wants is a uitable, not a cell array.

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


Image Analyst
Image Analyst 2012 年 9 月 26 日
I'm pretty sure you can't have a 2 by 2 array in one "cell" (here I'm using Excel's definition of cell, not MATLAB's definition of cell) of a uitable. The cells in a uitable can only be single numbers or strings.
As a workaround, you can have a blank (empty) separator column or row in between a 2 by 2 block of cells by putting in null for those rows or columns that you want blank. This will give the appearance of having those 2x2 arrays of numbers separated from each other.
  1 件のコメント
Lily
Lily 2012 年 9 月 26 日
Thx for the answer :) Is it possible to use some other function then the uitable? I'm so new to the table features in Matlab that I really have no idea what other functions would be more sutiable.

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

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by