filtering excel commands in matlab
8 ビュー (過去 30 日間)
古いコメントを表示
Hello, i have the attched file .
i want using script command to extract the table and filter the rows of the table where the dogs are.
so it basicky out of my excel table i need to get 3D array of of 1X1X2 (animal,size,Color)
dog M brown
dog M red
is there an effective way to do it in matlab commands?
Thanks.
0 件のコメント
回答 (2 件)
dpb
2022 年 9 月 10 日
編集済み: dpb
2022 年 9 月 11 日
tA=readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1121415/animals.xlsx');
tA=convertvars(tA,@iscellstr,'categorical');
tA
Now we've got the table, don't make piecemeal of it, use the variables of interest as grouping variables instead...
groupsummary(tA,'Animal')
When you subsequently add other data such as weights, ages, etc., etc., ... then you can compute statistics or whatever the same way with whatever functions you need.
tA.Animal=='dog'% see the logical addressing vector
tD=tA(tA.Animal=='dog',{'size','color'})
illustrates picking only the non-grouping variables since 'Animal' is now superfluous. To continue to carry it along anyway, use ":" for the column addressing vector.
2 件のコメント
dpb
2022 年 9 月 11 日
In general, it's wrong approach to physically separate tables unless it really is known that aren't going to use any of the other data for further analysis, but if you're adamant --
tDog=tA(tA.Animal=='dog',:);
Star Strider
2022 年 9 月 10 日
I have no idea what you want or the reason a 3D matrix is necessary.
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1121415/animals.xlsx')
T1u = unstack(T1,'size','Animal')
Different results are available with different argument permutations and more arguments as described in Name-Value Arguments.
.
4 件のコメント
Star Strider
2022 年 9 月 11 日
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/1121415/animals.xlsx')
Dogs = T1(strcmpi(T1.Animal,'dog') & strcmpi(T1.color,'red'),:)
.
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!