필터 지우기
필터 지우기

finding data in multiple rows and column of excel

조회 수: 1 (최근 30일)
badrul hisham
badrul hisham 2016년 4월 12일
댓글: badrul hisham 2016년 4월 12일
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.

채택된 답변

Guillaume
Guillaume 2016년 4월 12일
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])

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by