フィルターのクリア

Table did not show correctly after converting from cell array by using cell2table

3 ビュー (過去 30 日間)
isku
isku 2016 年 3 月 19 日
コメント済み: isku 2016 年 3 月 19 日
data = [32 47 51 41 46 30
46 38 34 34 52 48
48 38 43 41 21 24
25 29 33 45 51 32
32 27 23 23 34 35 ];
v = reshape(data,1,[]); % reshape array (matrix) to vector
nrClass = 5; % 5 classes
width = round(length(v)/ nrClass);
str = sprintf('Class %d - %d \n', min(v), min(v) + width );
f = length(v( v <= ( min(v) + width ) ) );
C = {str, v( v <= ( min(v) + width ) ), f };
for i=2:nrClass
% Expand size by assign data to a cell outside the current dimensions
C{i,1} = sprintf( 'Class %d - %d\n', min(v) + (i-1)*width, min(v) + i*width ); %class boundaries
C{i,2} = v( v > ( min(v) + (i-1)*width ) & v < ( min(v) + i*width ) ) ;
C{i,3} = length(C{i,2} ); % frequency
end
C13 = C(:,1:2:3) % Only column 1 and 3, or C13 = C(:,[1,3]) also works
% Convert the cell array, C13, to a table and specify variable names
T = cell2table(C13, 'VariableNames',{'Class' 'Frequent'})
Output:
T =
Class Frequent
___________ ________
[1x15 char] 6
[1x14 char] 5
[1x14 char] 6
[1x14 char] 3
[1x14 char] 5
  2 件のコメント
Stephen23
Stephen23 2016 年 3 月 19 日
So what is the "correct" table? What are you expecting?
isku
isku 2016 年 3 月 19 日
It should show some thing like:
frequent
________
Class 21 - 27 6
Class 27 - 33 5
Class 33 - 39 7
Class 39 - 45 3
Class 45 - 51 9

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

採用された回答

Jan
Jan 2016 年 3 月 19 日
編集済み: Jan 2016 年 3 月 19 日
The table seems to be fine, only the output suffers from the line breaks in the strings. So try to omit them:
data = [32 47 51 41 46 30; ...
46 38 34 34 52 48; ...
48 38 43 41 21 24; ...
25 29 33 45 51 32; ...
32 27 23 23 34 35 ];
v = reshape(data,1,[]); % reshape array (matrix) to vector
nrClass = 5; % 5 classes
width = round(length(v)/ nrClass);
str = sprintf('Class %d - %d', min(v), min(v) + width );
f = length(v(v <= (min(v) + width)));
C = {str, v(v <= (min(v) + width)), f};
for i = 2:nrClass
% Expand size by assign data to a cell outside the current dimensions
C{i,1} = sprintf('Class %d - %d', min(v) + (i-1)*width, min(v) + i*width); %class boundaries
C{i,2} = v(v > (min(v) + (i-1)*width) & v < (min(v) + i*width));
C{i,3} = length(C{i,2} ); % frequency
end
C13 = C(:, [1,3]);
T = cell2table(C13, 'VariableNames', {'Class' 'Frequent'})

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Type Conversion についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by