filtering excel commands in matlab
8 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
dpb
el 10 de Sept. de 2022
Editada: dpb
el 11 de Sept. de 2022
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 comentarios
dpb
el 11 de Sept. de 2022
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
el 10 de Sept. de 2022
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 comentarios
Star Strider
el 11 de Sept. de 2022
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'),:)
.
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!