finding data in multiple rows and column of excel
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
badrul hisham
el 12 de Abr. de 2016
Comentada: badrul hisham
el 12 de Abr. de 2016
hi, i have a table in excel that i have imported into matlab. the task was supposed to compare the calculations that i have gotten in matlab with the table in excel. for example:
my inputs are height, trunk index and a grouping value. lets say that i have the value of 54.5 for height,1.4 for trunk index and 1.5 for grouping value (the groups are endo, meso, ecto and balanced). the program will find where all these values are and then display the correct grouping. in this case it will display that the group is ecto.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/160898/image.jpeg)
another example :
if i have the value 54 for height, 1.25 for trunk index, and 4 for grouping value. the program will display that the group is endo and balanced.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/160900/image.jpeg)
i am new to matlab and i have been asking around but to no avail. can someone please show me how to do this? thank you very much for your help.
0 comentarios
Respuesta aceptada
Guillaume
el 12 de Abr. de 2016
I would use ismember to find the matching row, and simple comparison and logical indexing to find the groups:
%demo data. you would normally use readtable to import from excel
t = array2table([
54 1.05 5 1 1 1.5
54 1.15 4.5 1.5 1 2.5
54 1.25 4 2 1 4
54 1.35 3.5 2.5 1 4.5], ...
'VariableNames', {'Height', 'Trunk_Index', 'ENDO', 'MESO', 'ECTO', 'BALANCE'});
searchpattern = [54 1.25]; %height and trunk index
groupingvalue = 4;
%find matching row:
[found, row] = ismember(searchpattern, t{:, 1:2}, 'rows');
assert(found, 'could not find a row matching both height and trunk index');
matchgroups = t{row, 3:6} == groupingvalue;
groupnames = t.Properties.VariableNames([false, false, matchgroups])
Más respuestas (0)
Ver también
Categorías
Más información sobre Spreadsheets en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!