I've got a problem with my table output in Matlab. I'm sure it's a minor thing but google didn't have any answer for me, neither did the Matlab help.
我在Matlab中的表输出有问题。我确定这是一个小问题,但谷歌对我没有任何答案,Matlab也没有帮助。
As soon as the vector size of a variable is bigger than 3, the output will not display the actual value. Using the Matlab help example, this is what happens:
一旦变量的矢量大小大于3,输出就不会显示实际值。使用Matlab帮助示例,会发生以下情况:
Elements in variable BloodPressue = 3, output for table T produces: T =
变量BloodPressue = 3中的元素,表T的输出产生:T =
Age Height Weight **BloodPressure**
___ ______ ______ _________________
Smith 38 71 176 124 93 1
Johnson 43 69 163 109 77 1
Williams 38 64 131 125 83 1
Jones 40 67 133 117 75 1
Brown 49 64 119 122 80 1
Elements in variable BloodPressue = 4 (or bigger), output for table T produces: T =
变量BloodPressue中的元素= 4(或更大),表T的输出产生:T =
Age Height Weight **BloodPressure**
___ ______ ______ _____________
Smith 38 71 176 [1x4 double]
Johnson 43 69 163 [1x4 double]
Williams 38 64 131 [1x4 double]
Jones 40 67 133 [1x4 double]
Brown 49 64 119 [1x4 double]
How can I see the values for BloodPressure inside the table in the Matlab workspace?
如何在Matlab工作区中查看表内BloodPressure的值?
Hoping to get some help on this?
希望能得到一些帮助吗?
Many thanks!
3 个解决方案
#1
You can use the variable viewer.
您可以使用变量查看器。
Example:
A = table(magic(5))
A =
Var1
____________
[1x5 double]
[1x5 double]
[1x5 double]
[1x5 double]
[1x5 double]
In the workspace you can now double click on A
:
在工作区中,您现在可以双击A:
This will open the following viewer which shows you the contents of the table:
这将打开以下查看器,向您显示表的内容:
#2
If your question is only about viewing the data while your working with it, the above answer will help you. Should you want to manipulate the actual output, i.e. the appearance of your table when it is being printed etc., have a look at this link:
如果您的问题仅仅是在使用数据时查看数据,上述答案将对您有所帮助。如果您想要操作实际输出,即打印时表格的外观等,请查看此链接:
http://www.mathworks.com/help/matlab/ref/uitable-properties.html
So, you could try making the column header broader or adjusting the width of the column in general to match your data.
因此,您可以尝试使列标题更宽或通常调整列的宽度以匹配您的数据。
#3
In my case I solved my problem when I found a hack:
在我的情况下,当我发现黑客时,我解决了我的问题:
Given array:
num2str(Comp_Matrix(3,:)','%12.10f')
ans =
0.1297092395
0.1507424182
0.1586286637
0.1587259832
0.2880978647
0.4785836471
0.4786843575
0.8680238040
Using table I got:
使用表我得到:
table(num2str(Comp_Matrix(3,:)','%12.10f'))
ans =
Var1
___________
[1x12 char]
[1x12 char]
[1x12 char]
[1x12 char]
[1x12 char]
[1x12 char]
[1x12 char]
[1x12 char]
Well, you see that's a problem. Of course I can call table(Comp_Matrix(3,:)')
- it will display actual numbers, but I need to format output! So I tried a lot of things and when I used cellstr
the magic happened:
嗯,你看到这是一个问题。当然我可以调用table(Comp_Matrix(3,:)') - 它会显示实际数字,但我需要格式化输出!所以我尝试了很多东西,当我使用cellstr时,魔法发生了:
table(cellstr(num2str(Comp_Matrix(3,:)','%12.10f')))
ans =
Var1
______________
'0.1297092395'
'0.1507424182'
'0.1586286637'
'0.1587259832'
'0.2880978647'
'0.4785836471'
'0.4786843575'
'0.8680238040'
It is still not pretty, but it is readable at least. Also you can assign column to table in that way:
它仍然不漂亮,但它至少是可读的。您也可以通过这种方式为表分配列:
TheTable = table();
TheTable.Hack = cellstr(num2str([1 2 3 5; 4 5 6 5],'%1.2f '))
Hack
_____________________
'1.00 2.00 3.00 5.00'
'4.00 5.00 6.00 5.00'
If somebody knows a way to display long numbers without '' quotes - plz let us know too!
如果有人知道一种显示没有''引号的长数字的方法 - 请告诉我们!
#1
You can use the variable viewer.
您可以使用变量查看器。
Example:
A = table(magic(5))
A =
Var1
____________
[1x5 double]
[1x5 double]
[1x5 double]
[1x5 double]
[1x5 double]
In the workspace you can now double click on A
:
在工作区中,您现在可以双击A:
This will open the following viewer which shows you the contents of the table:
这将打开以下查看器,向您显示表的内容:
#2
If your question is only about viewing the data while your working with it, the above answer will help you. Should you want to manipulate the actual output, i.e. the appearance of your table when it is being printed etc., have a look at this link:
如果您的问题仅仅是在使用数据时查看数据,上述答案将对您有所帮助。如果您想要操作实际输出,即打印时表格的外观等,请查看此链接:
http://www.mathworks.com/help/matlab/ref/uitable-properties.html
So, you could try making the column header broader or adjusting the width of the column in general to match your data.
因此,您可以尝试使列标题更宽或通常调整列的宽度以匹配您的数据。
#3
In my case I solved my problem when I found a hack:
在我的情况下,当我发现黑客时,我解决了我的问题:
Given array:
num2str(Comp_Matrix(3,:)','%12.10f')
ans =
0.1297092395
0.1507424182
0.1586286637
0.1587259832
0.2880978647
0.4785836471
0.4786843575
0.8680238040
Using table I got:
使用表我得到:
table(num2str(Comp_Matrix(3,:)','%12.10f'))
ans =
Var1
___________
[1x12 char]
[1x12 char]
[1x12 char]
[1x12 char]
[1x12 char]
[1x12 char]
[1x12 char]
[1x12 char]
Well, you see that's a problem. Of course I can call table(Comp_Matrix(3,:)')
- it will display actual numbers, but I need to format output! So I tried a lot of things and when I used cellstr
the magic happened:
嗯,你看到这是一个问题。当然我可以调用table(Comp_Matrix(3,:)') - 它会显示实际数字,但我需要格式化输出!所以我尝试了很多东西,当我使用cellstr时,魔法发生了:
table(cellstr(num2str(Comp_Matrix(3,:)','%12.10f')))
ans =
Var1
______________
'0.1297092395'
'0.1507424182'
'0.1586286637'
'0.1587259832'
'0.2880978647'
'0.4785836471'
'0.4786843575'
'0.8680238040'
It is still not pretty, but it is readable at least. Also you can assign column to table in that way:
它仍然不漂亮,但它至少是可读的。您也可以通过这种方式为表分配列:
TheTable = table();
TheTable.Hack = cellstr(num2str([1 2 3 5; 4 5 6 5],'%1.2f '))
Hack
_____________________
'1.00 2.00 3.00 5.00'
'4.00 5.00 6.00 5.00'
If somebody knows a way to display long numbers without '' quotes - plz let us know too!
如果有人知道一种显示没有''引号的长数字的方法 - 请告诉我们!