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!