Extract cell value based on row contents
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a table with 4 columns (id1, id2, HB, and FENE) and many thousands of rows. From this I would like to create a new table of HB data, extracted if the id1 and id2 contain particular values. For instance:
id1 id2 HB FENE
1 28 0.718 281
1 31 0.572 256
1 07 0.182 413
2 28 0.271 361
2 31 0.725 249
2 07 0.012 992
1 28 0.381 438
2 31 0.991 913
if I am interested in the id combinations of [1,28] and [2,31], I want to produce the table:
1+28 2+31
0.718 0.725
0.381 0.991
In the dataset there will always be the same number of id combinations (i.e. if there are five rows containing [1,28], there are also five rows of [2,31]).
My current process is:
id1 = [1 2 3 4 5]
id2 = [28 31 34 37 40]
dataFile = file.txt
dataOutput = zeros(1,5)
for k = 1:5
head1 = strand1(k)+"+"+strand2(k)
if dataFile{:,1} == strand1(k)
if dataFile{:,2} == strand2(k) %both conditions must be true to proceed
?? extract data from this row, in col 3, and append to dataOutput in col k, new row
end
end
%loops in k=1 until all instances are found
%do i have to define how many times to loop for k=1?
end
outputTable = array2table(dataOutput)
outputTable.Properties.VariableNames(1:5) = {'head1','head2','head3','head4','head5'}
Thank you very much for any pointers or advice.
댓글 수: 0
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!