필터 지우기
필터 지우기

How can I display data inside a table in expanded form?

조회 수: 7 (최근 30일)
Mohamed Abd El Raheem
Mohamed Abd El Raheem 2018년 9월 3일
댓글: dpb 2018년 9월 6일
Greetings... I have a simple strcuture array (s) of two fields: name and data. Assume the array length is two. I wanted to display it in a table form in the command window. So, I used {struct2table} and generated a table T and displayed it in the command window. The problem is that, the table displays the data column in a collapsed form. Assume that s(1).data and s(2).data are (1 x 7) double arrays. The table displays them in that collapsed form: [1x7 double]. I want to expand each one inside the table and show it detailed, like [1.2 3.6 ...] in its place in the table. How can this be done? Thanks in advance.
  댓글 수: 4
Mohamed Abd El Raheem
Mohamed Abd El Raheem 2018년 9월 6일
편집: Mohamed Abd El Raheem 2018년 9월 6일
My apologize to every one for my late response.
@dpb: Thank you very much for your response. Is there any other tool in MATLAB to achieve that display function? I really need to view some columns in the table form, but with these data expanded. I need to see the name and the expanded array (just a row vector, 1x7 double array as stated in the above example) related to it besides, as if it is a table. I have about 32 rows, and I want to view them in this form: name_____________ [n1 n2 ...n7].
We have these data in a strcuture array as mentioned before.
@Walter Roberson: Thank you also for your answer, Walter. In present, I don't use tables in anything in my work, I just resorted to them because I supposed they have the display feature I need. If there is no other method in MATLAB to achieve the required display, I would like to hack the code, if this is allowed.
dpb
dpb 2018년 9월 6일
Well, Matlab is not a spreadsheet application; presentation is not it's strong suit.
Have you investigated the workspace variable viewer? It would show the elements of the field in the structure in a spreadsheet-like interface, but it can't place multiple variables on the same page such as what a table is able to consolidate.

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2018년 9월 6일
If you are only using table to display, then what you should be using instead is sprintf() or sprintf() with formats that include widths (possibly calculated) and possibly negative widths if you want left alignment.
>> sprintf('%-10s', 'hello')
ans =
'hello '
>> sprintf('%10s', 'hello')
ans =
' hello'
In particular, suppose you have a cell array column vector Names and a double array Values with the same number of rows.
ncol = size(Values,2);
fmt = ['%-15s ', repmat('%15g ', 1, ncol-1), '%15g\n'];
data = [Names, mat2cell(Values)] .'; %transpose is important
fprintf(fmt, data{:});

카테고리

Help CenterFile Exchange에서 Structures에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by