finding data in multiple rows and column of excel
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
badrul hisham
am 12 Apr. 2016
Kommentiert: badrul hisham
am 12 Apr. 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.
0 Kommentare
Akzeptierte Antwort
Guillaume
am 12 Apr. 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])
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Spreadsheets finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!