フィルターのクリア

accessing table data in different forms

1 回表示 (過去 30 日間)
Ege
Ege 2014 年 10 月 25 日
回答済み: Ege 2014 年 10 月 26 日
Hi I have T table as follows.
LastName = {'Smith';'Johnson';'Williams';'Jones';'Brown'};
Age = [38;43;38;40;49];
FirstName = {'Amanda' ;'Brenda';'Carl'; 'Denis'; 'Ethan'};
Something = {'String1' ;'String2';'String2'; 'String1'; 'String5'};
Weight = [176;163;131;133;119];
FavoriteColor = {'blue' ;'red' ;'yellow'; 'orange' ;'colorblind' };
T = table(Age,FirstName,Weight,FavoriteColor,Something,'RowNames',LastName)
T.FavoriteColor= categorical(T.FavoriteColor);
T.Something= categorical(T.Something);
when I use
A=T(:,5);
I get a variable A which is a table as well. But when I use
A=T.Something;
I get a variable A which is a categorical value like the ones is column Something. I want to use loops so I need to use the first one with indices but I want the result in the second one. What should I do?
  2 件のコメント
Geoff Hayes
Geoff Hayes 2014 年 10 月 25 日
Ege - what are you trying to achieve? You mention that you want to use loops, but what do you want to use the loops for?
Ege
Ege 2014 年 10 月 25 日
Well I just started the project I will use it for many things but for now, I have divided my dataset into 2 tables which holds categorical and non categorical data. I'm currently using the categorical one and try to implement a histogram on that since usual histogram function does not work on categorical data. My dataset is huge so at first I will use the categorical column of the T table I mentioned in the question. When I use it like below, it works fine.
a=T.Something;
hist=zeros(size(a,1),1);
u=unique(a);
for i=1: size(a,1)
for j=1: size(u,1)
if isequal(a(i),u(j))
hist(j)=hist(j)+1;
end
end
end
for i=1:numel(hist,1)
if isequal(hist(i),0)
hist(i)=[];
end
end
histogram = table(u(:),hist(:));
But when I try using
a=T(:,5);
the histogram does not work I get wrong results in hist().

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

採用された回答

Ege
Ege 2014 年 10 月 26 日
accesing it like
a=T{:,5};
solved my problem. Hope this helps someone as well :D

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by