フィルターのクリア

How to show a one column matrix with muiltcolumn

3 ビュー (過去 30 日間)
Yode
Yode 2017 年 7 月 16 日
編集済み: Yode 2017 年 7 月 17 日
I have a matrix,such as
[1:17]'
the matlab will show it in a long shape,
I have to say it waste my space too much. So I hope to show it with 4 column. If I'm in Mathematica I just sove it like this
It's possible in matlab?

採用された回答

Yode
Yode 2017 年 7 月 17 日
編集済み: Yode 2017 年 7 月 17 日
As some improve,I complete this function almost perfect work for me
function multicolmn(mat,col)
if nargin<2
col=fix(floor(sqrt(numel(mat))));
end
if isnumeric(mat)
disp(sprintf([repmat('%d\t',1,col) '\n'], mat))
elseif iscell(mat)
n=max(cellfun(@length,mat))
disp(sprintf([repmat(sprintf('%%-%ds\t',n),1,col) '\n'],mat{:}))
end
It will show the input like a square shape as much as possible.Such as
>> multicolmn(1:17)
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
17
Or
clear;
h=figure;
t=set(h,'pointer');
>> multicolmn(t)
arrow ibeam crosshair watch
topl topr botl botr
circle cross fleur custom
left top right bottom
hand
Of course,you can specify the colum you want to show
>> multicolmn(t,3)
arrow ibeam crosshair
watch topl topr
botl botr circle
cross fleur custom
left top right
bottom hand

その他の回答 (2 件)

Walter Roberson
Walter Roberson 2017 年 7 月 16 日
You would need to override the display() method for class "double", which would risk messing up the display of composite data types such as struct.
It would be safer to write a little routine that did this kind of display only when you asked for it.
One of the tricky parts is figuring out how wide the command window is, and figuring out the font size, so that you can figure out how many characters across you can display. The number of columns that fit will then depend upon the number of characters required to represent the largest number that happens to fit in that column -- for example you made your second column wider to fit the "10". But as you change the number of numeric columns then a wide number that was near the end of one column might move to a different column, which can change the number of characters required for the column, which can require changing the number of numeric columns again...It might be easiest to not try to narrow down the parameters by calculating from both sides, and to instead assume the maximum number of numeric columns, figure out whether the data would fit considering the widest in each, if not then reduce the number of numeric columns by 1, keep going until everything fits. (If you get down to 1 numeric column and it doesn't fit, then your command window is too small!)
  3 件のコメント
Walter Roberson
Walter Roberson 2017 年 7 月 16 日
Your example shows the user passing in the number of columns. Is that an acceptable interface, or does it need to figure out how many columns to use?
Yode
Yode 2017 年 7 月 16 日
編集済み: Yode 2017 年 7 月 16 日
Yes,I need it to show 4 column.The number of column don't need to caculate

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


Yode
Yode 2017 年 7 月 16 日
編集済み: Yode 2017 年 7 月 16 日
I get an answer in overflow
disp(sprintf([repmat('%d\t',1,4) '\n'], 1:17))
  1 件のコメント
Walter Roberson
Walter Roberson 2017 年 7 月 16 日
That is workable code, but I do note that it presents the output in a different order than you asked for, and it has the empty areas in a different location.

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

カテゴリ

Help Center および File ExchangeParticle & Nuclear Physics についてさらに検索

Community Treasure Hunt

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

Start Hunting!