Extract cell value based on row contents
3 views (last 30 days)
Show older comments
Karuna Skipper
on 13 Feb 2023
Commented: Karuna Skipper
on 13 Feb 2023
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 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Matrix Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!