Effacer les filtres
Effacer les filtres

finding data in multiple rows and column of excel

1 vue (au cours des 30 derniers jours)
badrul hisham
badrul hisham le 12 Avr 2016
Commenté : badrul hisham le 12 Avr 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.
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.
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.

Réponse acceptée

Guillaume
Guillaume le 12 Avr 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])
  1 commentaire
badrul hisham
badrul hisham le 12 Avr 2016
thank you so much! this works amazing

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by